Dealing with long file and path names - Copy-Item

Good Afternoon all,

I have a powershell script that deals with leavers - it utilizes the copy-item cmdlet but occasionally I get a copy error about long file or path names.  Please could you let me know if there is anything I can use or an alternative method to deal with this?

Thanks for any help.

  • PowerShell utilizes the same Windows APIs that introduce this limitation, so the short answer is not using the default cmdlet/apis. Robocopy is a great alternative though, it is a solid tool that is not bothered by the long path limitation and it can be called from PowerShell. 

    The alternative options, to be able to do this from PowerShell are the following:

    • Nesting mapped network drives to transfer files and folders in long paths
    • Nesting symbolic links to transfer files and folders in long paths
    • Using an alternative API to transfer the files (Advanced and experimental)
    I wrote a function that can detect long paths, it also uses robocopy to detect the long paths. It is available here: Get-LongPathName

  • Good Afternoon Jaap,

    Is there a guide on utilizing robocopy within my powershell script please?


    Ahh I have just seen it is built into Windows 8 - I thought it was a seperate tool, looking at your function I guess I can just call it by using:

    robocopy.exe in my script?

    I will check out your function, thanks :)

  • There is no guide, you can just type robocopy c: d: and it will start copying. There are no additional considerations aside from different variables in PowerShell when compared to the command prompt, eg: $env:systemroot instead of %systemroot%. Have a look at robocopy /? for the variable or read more about it in this community page with some common usage scenarios:

    Robocopy and a Few Examples

    Let me know if you have any further questions, if you can show some of your code and what you intend to use robocopy for I can give some additional feedback.


  • Powershell wont help in this case I guess. You can try Robocopy but it didn't helped me at all and made the situation worse. I then tried GS Richcopy 360 which really helped me out. Solved the issue in no time. I am using its enterprise edition currently! Give it a shot and try its trial version.

  • Long Path Tool can eliminate the following error messages:

    - Path too long

    - Filename too long

    - Path too deep

    - Destination path too long

    It also allows you to delete, copy and rename long path files.

  • """""""I recommend three solutions:

    1. (if the path is too long) First copy the folder to upper levels in windows explorer and then move it to your local computer
    (if file names are too long) First try to zip/rar/7z them with an archive application and then 2. copy the archive file to your local computer and then extract the contents.
    3. Use third party apps. I suggest to use gs richcopy 360. It is """"""""The Fastest Copy/Delete Software on Windows."""""""" It supports UNICODE and over MAX_PATH (260 characters) file path names.
    All of these suggestions assume you have some sort of write access on the network shared folder/computer. If you can't do any of these then you might need help from your administrator"""""""