Recursively copy folders with long file names (more than 260 chars)

Transformer picture Transformer · Aug 24, 2017 · Viewed 8.2k times · Source

I am trying to automate copy/replication of drives. Many of the drives have long file names, that fail the process midway.

I was using this copy command, but both these fail.

XCOPY /E c:\folder-you-want-to-copy\*.* C:\destinationfolder\ 

copy-item -Path K:\* -Destination E:\ -Recurse -Force

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 260 characters.

I then tried SO help power shell from here and SO help here, but the enable option was missing in Win 10 policy for my machine

How can I recursively copy the files from one drive to another drive with the long file names/path?

Answer

henrycarteruk picture henrycarteruk · Aug 24, 2017

robocopy does not adhere to the 260 character limit (unless you usie the /256 switch):

robocopy K:\ E:\ /E

/E is to Copy Subfolders, including Empty Subfolders, if you don't want empty folders copied use /S instead.

Full robocopy syntax