Windows – File name too long when copying to a directory with shorter file path

windowswindows 10

This is weird.

I have a meanJs installation, the contents of which I copied to another folder.

Original folder path: C:\work\defaults\mean_0.3.3

File contents copied to: C:\work\defaults\a

As you can see it's obvious that the file contents are copied to a folder with a shorter name, so the file name too long error should not come, yet it does.

Is this a windows 10 bug?

Tried to do the it with copy-item command on the powershell and this is part of the output (it goes on for a while):

PS C:\work\defaults> copy-item .\mean_0.3.3\ -destination .\b -recurse
copy-item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260
characters, and the directory name must be less than 248 characters.
At line:1 char:1
+ copy-item .\mean_0.3.3\ -destination .\b -recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (test-delayed-http-upload.js:FileInfo) [Copy-Item], PathTooLongException
    + FullyQualifiedErrorId : CopyDirectoryInfoItemIOError,Microsoft.PowerShell.Commands.CopyItemCommand

copy-item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260
characters, and the directory name must be less than 248 characters.
At line:1 char:1
+ copy-item .\mean_0.3.3\ -destination .\b -recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (test-delayed-stream-auto-pause.js:FileInfo) [Copy-Item], PathTooLongExceptio
   n
    + FullyQualifiedErrorId : CopyDirectoryInfoItemIOError,Microsoft.PowerShell.Commands.CopyItemCommand

copy-item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260
characters, and the directory name must be less than 248 characters.
At line:1 char:1
+ copy-item .\mean_0.3.3\ -destination .\b -recurse
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (test-delayed-stream-pause.js:FileInfo) [Copy-Item], PathTooLongException
    + FullyQualifiedErrorId : CopyDirectoryInfoItemIOError,Microsoft.PowerShell.Commands.CopyItemCommand

Best Answer

The fully qualified path of some subdirectory (before or after copying) is too long. This is a limitation of the cmdlet (and to some extent, the API it targets).

Easiest workaround is to use Robocopy: https://technet.microsoft.com/en-us/library/cc733145.aspx

Related Question