Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
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
add comment

6 Answers

up vote 5 down vote accepted

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

share|improve this answer
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. –  Jimmy Shelter 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
add comment

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)

share|improve this answer
add comment

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

share|improve this answer
add comment

Try using xcopy instead of copy.

share|improve this answer
add comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.