Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum Import-PWDocuments issues with drive as InputFolder and long path
    • Sign In

    • State Suggested Answer
    • Replies 10 replies
    • Answers 1 answer
    • Subscribers 67 subscribers
    • Views 1601 views
    • Users 0 members are here
    • Import-PWDocuments
    • powershell
    • pwps_dab

    Import-PWDocuments issues with drive as InputFolder and long path

    Mathieu Bengle
    Offline Mathieu Bengle over 1 year ago

    Hi,

    I'm running into two issues with cmlet Import-PWDocuments.

    1- When $Inputfolder path is located on my c drive, I can import every file in sub-folders, but when it is located on a drive only folder structure is imported with the fil in the parent folder.

     -  from my C drive --> $InputFolder = '\\localhost\c$\Users\MYUSERNAME\Desktop\temp\1.0 Intrants'

    VERBOSE: Found 9 files.
    VERBOSE: End getting folders.
    VERBOSE: Found 4 folders

    - from drive --> $InputFolder = '\\localhost\c$\Users\MYUSERNAME\MYCOMPANY O365\GROUPNAME\1.0 Intrants'

    VERBOSE: Found 1 files.
    VERBOSE: End getting folders.
    VERBOSE: Found 4 folders

    2- I get error code 58183 for a folder because string value is too long. Unfortunatly I cannot change folder and file names. Windows long path is enabled as well.

    VERBOSE: Looking for ProjectWise folder '_Sandbox\Script testing\Powershell\SP to PW\Incoming\20210226_6_Étude d'opportunité_Corridor élargi «A-15-prolongement de l'
    A-13»'
    WARNING: Error creating folder '_Sandbox\Script testing\Powershell\SP to PW\Incoming\20210226_6_Étude d'opportunité_Corridor élargi «A-15-prolongement de l'A-13»' Er
    ror 58183

    How can I fix this?

    Config:

    Microsoft Windows NT 10.0.19042.0
    Windows long paths enabled
    PSVersion: 5.1.19041.1237
    pwps_dab: 1.30.10.0
    ProjectWise 03.434

    $ProjectWiseFolder = '_Sandbox\Script testing\Powershell\SP to PW\Incoming'
    $InputFolder = '\\localhost\c$\Users\MYUSERNAME\MYCOMPANY O365\GROUPNAME\1.0 Intrants'
    
    New-PWLogin -UseGui -Verbose
    
    Import-PWDocuments -InputFolder $InputFolder -CreateVersions -DefaultStorage Storage -ExcludeSourceDirectoryFromTargetPath -IncludeEmptyFolders -ProjectWiseFolder $ProjectWiseFolder -SuppressOutput -Verbose
    
    Undo-PWLogin -Verbose

    Thanks for your help

    • Sign in to reply
    • Cancel

    Top Replies

    • Kevin van Haaren
      Offline Kevin van Haaren Fri, Dec 3 2021 5:12 PM in reply to Dan Williams +2
      There is another trick you can use here as well. This works if the really long path is on a mapped network drive or on your c: drive too. The command line program subst allows you to substitute a drive…
    • Dan Williams
      Offline Dan Williams Fri, Dec 3 2021 6:44 PM in reply to Kevin van Haaren +1
      Thanks Kevin van Haaren ! I haven't used that command in years, but I do remember using it in the past. FWIW, I got curious if there was a way to do this in PowerShell, and there is. If you are interested…
    • Kevin van Haaren
      Offline Kevin van Haaren Sun, Dec 5 2021 7:20 PM in reply to Dan Williams +1
      nice. i experimented a bit, drives created with subst will show up with Get-PSDrive (immediately, don't need to relaunch ps). Using new-psdrive to create a mapping to the local system won't show up in…
    • Dan Williams
      0 Offline Dan Williams Fri, Dec 3 2021 4:27 PM

      I won't address your specifics, but when I have run into similar "long paths" issues in the past for various import operations (not all for ProjectWise), one "trick" that I learned from a colleague years ago was to create a share far enough down the path for the source that "works" and mount that share as a drive.  Of course if the paths are still too long then you might have to look for an alternative method.

      So you could try creating a share for perhaps a folder "down the tree" like the "GROUPNAME" folder, and then mount that share as drive X:.  Then you should be able to import from drive X: at the location in your datasource that matches up with what you intend the full path to be.

      HTHs

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Reject Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Fri, Dec 3 2021 5:12 PM in reply to Dan Williams

      There is another trick you can use here as well. This works if the really long path is on a mapped network drive or on your c: drive too.

      The command line program subst allows you to substitute a drive letter for any path.

      > subst x: j:\dir1\dir2\dir3\dir4
      
      > subst /?
      Associates a path with a drive letter.
      
      SUBST [drive1: [drive2:]path]
      SUBST drive1: /D
      
        drive1:        Specifies a virtual drive to which you want to assign a path.
        [drive2:]path  Specifies a physical drive and path you want to assign to
                       a virtual drive.
        /D             Deletes a substituted (virtual) drive.
      
      Type SUBST with no parameters to display a list of current virtual drives.
      

      Running the first command in that, subst x: J:\dir1\dir2\dir3\dir4 allows you to use the shortcut x: for all those paths.

      you can used subst x: /d to delete it when done

      just running subst with no options will display any currently substituted drives.

       

      • Cancel
      • Vote Up +2 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Dan Williams
      0 Offline Dan Williams Fri, Dec 3 2021 6:44 PM in reply to Kevin van Haaren

      Thanks Kevin van Haaren!  I haven't used that command in years, but I do remember using it in the past.  

      FWIW, I got curious if there was a way to do this in PowerShell, and there is.  If you are interested, check out this Cmdlet:

      New-PSDrive

      I didn't test this out to see if it works with ProjectWise, but I did notice the note in the documentation about the setting the "Scope" parameter value to "Global" to make the drive persist out of the current scope.  Not sure if that means it would persist outside of PowerShell or not.

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Mathieu Bengle
      0 Offline Mathieu Bengle Fri, Dec 3 2021 10:57 PM in reply to Dan Williams

      It seems that the folder name has too many characters because all other folders with the same path have been created. If I add this folder directly in PW explorer, I also get error for folder name too long. Is there a way to force this?

      Also, do you have any idea why the files are not imported when I use the Import-PWDocuments cmdlet with a drive like Onedrive mapped to X as the input folder :?

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Dan Williams
      0 Offline Dan Williams Sat, Dec 4 2021 3:17 AM in reply to Mathieu Bengle

      Mathieu Bengle, 

      If you are asking what the maximum length of a folder name can be in ProjectWise, the answer is 63, and no, there isn't a way to force a folder to have a longer name.

      However, the folder's' description can be a maximum of 127 characters.  You could come up with a naming scheme to shorten the folder's name to fix and to be unique, but then use the "real" name as the folder's description.  This way you could then enable the user setting to use descriptions instead of names.

      As for why the files are not imported when you use the Import-PWDocuments Cmdlet with Onedrive mapped to a drive letter?  Not sure, but the underlying code for Import-PWDocuments looks like it uses FindFirstFile and the underlying code might not account for network shares as I see some comments in Microsoft's documentation about some limitations when trying to find files on network shares.

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    >

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies