1

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?

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
Transformer
  • 6,963
  • 2
  • 26
  • 52

1 Answers1

4

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

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
  • will try this and let you know, 1) do I need to install robocopy? how long would it take for 1 or 2TB over USB 3 2) its not mirroring, correct? just copy the files and structure? – Transformer Aug 24 '17 at 17:36
  • 1
    robocopy is included with most modern versions of windows, can't comment on time as it depends on the number of files and their size. Yes that's a straight copy, mirroring uses a different switch (check syntax if you wanted this) – henrycarteruk Aug 25 '17 at 10:05
  • If it crashes, is there a continue from the current place option, and can it do a parallel copy to speed things up. – Transformer May 18 '21 at 17:39
  • @Transformer robocopy doesn't have a resume option per-se, but it skips over files that have not changed so you can re-run pretty quickly. For multi-threaded take a look at the [/MT switch](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy)... if it's crashing regularly you've probably got a very dodgy file as it's a really solid program! – henrycarteruk May 20 '21 at 09:19