Copy Folders and subfolders on a directory to another using batch file

batch-filecommand line

I have a folder on my computer that I want to schedule (using task scheduler) the backup every day. What I want to do is, if the destination folder already contains the folder (including the subfolder and files) from the source path, it will be skipped and continue copying the other folders that are not yet on the destination folder (I don't want to overwrite existing folders or subfolders or even the files). How could I do that to my batch file?

e.g.
source folder contains:
Folder1
Folder2
Folder3

destination folder contains:
Folder1 (same folder on the source)
Folder2 (same folder on the source)

The command will copy the Folder3 only.

Best Answer

This will mirror the source to the target and skip files that already exist, but will also remove files (from the target) that no longer exist in the source - Vista and higher have Robocopy. XP can download it.

robocopy "c:\source" "d:\target" /mir

or a UNC path

robocopy "\\server1\share\" "\\server2\\share2" /mir