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!

1
  • 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. Sep 30, 2009 at 21:35

6 Answers 6

5

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

3
  • 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, 2009 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. Aug 26, 2009 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 ^^ Aug 26, 2009 at 14:28
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)

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

Try using xcopy instead of copy.

0

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

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .