复制到文件路径较短的目录时文件名太长

复制到文件路径较短的目录时文件名太长

这很奇怪。

我有一个 meanJs 安装,我将其内容复制到了另一个文件夹。

原始文件夹路径:C:\work\defaults\mean_0.3.3

文件内容复制到:C:\work\defaults\a

如您所见,很明显文件内容被复制到了名称较短的文件夹中,因此不应该出现文件名太长的错误,但事实却并非如此。

这是 Windows 10 的一个错误吗?

尝试使用 powershell 上的命令执行该操作copy-item,这是部分输出(持续一段时间):

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

答案1

某些子目录的完整路径(复制前或复制后)太长。这是 cmdlet 的限制(在某种程度上也是其所针对的 API 的限制)。

最简单的解决方法是使用 Robocopy:https://technet.microsoft.com/en-us/library/cc733145.aspx

答案2

您可以使用 robocopy 命令,但我发现更简单(虽然有点慢)的方法是压缩文件夹,复制压缩文件,然后解压缩。或者,您可以将嵌套很深的文件夹移动到更高级别的目录,将其复制过来,然后将其移回嵌套位置。

不确定为什么会这样,但根据本文windows 的文件长度有上限姓名,但由于某种原因,在复制时会检查整个文件路径的长度。

所以你的文件路径之所以这么长,首先是因为它是手动创建的,而不是复制过来的。或者它是通过程序创建的,或者任何其他不涉及复制的方法。至少这是我的猜测

相关内容