2

I need to copy a full directory tree (aka recursive copy) with a bat files on windows. On *nix systems I use the -R argument on the copy command, like so:

cp -R fromDir toDir

and that did the job. I could not find anything similar in the windows "man pages" of the copy command.

Thanks!

raoulsson
  • 4,633
  • 10
  • 32
  • 29
  • Windows no longer has anything similar to man. DOS did have fairly good help files but they've been abandoned. However, most Windows command line programs will have some level of help built in, which is accessed by using /? as a parameter, similar to --help in nix. – John Gardeniers Sep 30 '09 at 21:35

6 Answers6

10

Copy doesn't handle recursion. Use robocopy instead. On Windows 2008 it's already there and in the Path. On Windows 2000 and 2003 it's in the resource kit. Flags you'll want are /S /Z /ETA.

/S recursion /Z restartable node /ETA tell me how long the current file will take (optional)

mrdenny
  • 27,074
  • 4
  • 40
  • 68
5

The /s option on XCOPY will handle sub-directories (except blank ones).

Justin Scott
  • 8,748
  • 1
  • 27
  • 39
  • 4
    I would also add the /e switch to capture empty direcoties /v to verify the file /x to copy ownership/acl and audit setting and /k to copy attributes /z if over the network for restartable mode – Zypher Aug 26 '09 at 13:54
  • /s/e/c/h/r/k/y are my standard xcopy switches, memorised at this point in time. /x does audit settings as well as ACL, if you want ACL only include /o in the mix. – Maximus Minimus Aug 26 '09 at 14:06
  • 1
    Interestingly enough in Vista, xcopy prints a "use robocopy instead" message indicating xcopy is deprecated... but in Windows 7 xcopy does not print this message anymore... I'm not sure I'm annoyed or relieved - two strong copy commands seems like one too many, oh well ^^ – Oskar Duveborn Aug 26 '09 at 14:28
2

I would use Robocopy /E /COPYALL /MIR /ETA /LOG:FILE.log /TEE "SOURCE DIR" "DESTINATION DIR"

Example: robocopy.exe /E /COPYALL /MIR /ETA /LOG:C:\copy.log /TEE "C:\SourceDirectory\\" "C:\DestinationDirectory\\"

/E: copy subdirectories, including Empty ones.
/COPYALL: Will copy all security flags and timestamps on files
/MIR: Will make an exact copy of the source. So if you copy it once, and then copy over a second time, it will process deletes along with new files.
/ETA: show Estimated Time of Arrival of copied files.
/Log: Creates a log file
/TEE: output to console window, as well as the log file.

There are many different options for robocopy if you do the /? for more advanced usage.

You can also use the GUI version: http://technet.microsoft.com/en-us/magazine/2006.11.utilityspotlight.aspx

0

cpx.exe from the utx project supports recursive copying and recursive wildcards for simple and powerful selection of the files to copy.

0

Try using xcopy instead of copy.

Dave Drager
  • 8,315
  • 28
  • 45
0

I suggest xcopy /mir [from] [to] if you wish to preserve permissions.

Scott
  • 1,062
  • 1
  • 11
  • 11