Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell: 'The fully qualified file name must be less than 260 characters'

I tried to use powershell command copy-item as xcopyto copy content of one disk to another one.

copy-item -Path h:\* -Destination g:\ -Recurse -Force

However, I encountered the following errors:

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.

I got these errors enough to discourage manually search and copy files or folders with long paths. What is the best way to avoid this problem?

like image 610
Loom Avatar asked Dec 20 '22 23:12

Loom


1 Answers

As far as I know robocopy deals with this automatically (at least you would have to disable support for long paths explicitly). So you could use

robocopy h:\ g:\ /E

if you're not too adverse to a native command instead of a pure PowerShell solution.

Usually you can prepend \\?\ to a path to allow handling paths with up to 32k characters but it could well be that this might not help with .NET.

like image 140
Joey Avatar answered May 12 '23 08:05

Joey