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 have 2 folders, the first:

C:\folder1
C:\folder1\subfolder\a.txt
C:\folder1\subfolder\b.txt

and the second:

C:\folder2
C:\folder2\subfolder\a.txt

I would like to merge them like so:

C:\folder2
C:\folder2\subfolder\a.txt (folder 2's a.txt)
C:\folder2\subfolder\b.txt

Description of what I want:

Is there a simple DOS command to copy all of the folders, subfolders and files from folder1 TO folder2, but if something exists in folder2 I do not want to overwrite it. If folder 1 has files that do not exist in folder2, I want them to be copied in.

Note: both folder1 and folder2 share common subfolder names.

Note 2: Folder2 is several TB's so I really have to copy into folder 2. Folder1 is only several GB.

I can't do this in windows explorer because there is no option to say overwrite files? No to all.

share|improve this question

4 Answers 4

up vote 5 down vote accepted

Yes, the robocopy.exe resource kit utility I think was made part of the OS with Windows 2003. You can specify all sorts of options as to what gets overwritten or not.

By default, robocopy won't overwrite same files, just newer versions over old - it's a folder syncing tool, mainly.

If you want to avoid any sort of overwrite, this might work,

robocopy C:\FOLDER1 C:\FOLDER2 /e /xc /xn /xo

where,

/e is copy all subfolders, even empty ones.
/xc is exclude changed files.
/xn is exclude newer files.
/xo is exclude older files.

I recommend you test first with these additional switches,

robocopy C:\FOLDER1 C:\FOLDER2 /e /xc /xn /xo /l /log+:robocopy.txt /np /ndl /tee

where,

/l is just list, don't actually do anything. Remove this switch when you're happy with what robocopy will do.
/log+: appends output to a text file, so you can study it, or /log:, which overwrites the log each time.
/np prevents "% done" progress info in the log.
/ndl is a personal preference for a cleaner log output, but maybe leave this switch out until you're comfortable with how robocopy works.
/tee shows you output on the screen as well as the log.

share|improve this answer
    
nice, thank you –  Brian R. Bondy Jun 7 '09 at 16:06

You could use the /Y switch of XCOPY or use ROBOCOPY ("Robust File Copy for Windows" as part of the Windows Server 2003 Resource Kit Tools), which by default overwrites without asking for confimation.

share|improve this answer

Another nice option is to install rsync on the Windows machine, and you get all sorts of great functionality. DeltaCopy is one tool based on rsync: http://www.aboutmyip.com/AboutMyXApp/DeltaCopy.jsp

share|improve this answer

You could also just use explorer to copy the contents of folder2 to folder1 (or to a copy of folder1). In that case you can overwrite existing files in folder1 and therefore files in folder2 'win'.

Am i missing something?

share|improve this answer
    
Yes, folder2 is several TBs large and folder1 is only a few GB. –  Brian R. Bondy Jun 7 '09 at 17:42

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.