问题
I've been trying to create this script that basically mirrors two sets of folders and it's content (including subfolders), but only copy files that are newer than the ones that already exist. I tried doing this by writing a vbscript, but it turns out that I manualle need to scan each subfolder and then it's content. And then that subfolder's content as well and so on and so forth.
So I'm wondering if anyone knows if this can be done with Robocopy?
回答1:
ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR
CORRECTION
ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR /XO
回答2:
In short - yes - this is nice and simple with RoboCopy. By default it only copies changed files anyway, and won't bother copying unchanged files. You just need to add one argument to get it to exclude files where the destination exists and is newer.
The syntax of RoboCopy is a little bit quirky, so you may want to read more from here.
You probably want something like this:
RoboCopy.exe %sourceDir% %targetDir%\ *.* /xo
%sourceDir%
- your source directory
%targetDir%
- your target directory
*.*
- the files in the source directory to copy
/xo
- exclude file if the destination already exists and is newer.
[Edit in response to comment]
If you are saying you want to remove files from the destination directory that no longer exist in the source directory, then I believe the switch /purge
does this.
来源:https://stackoverflow.com/questions/2871931/robocopy-compare-modified-dates-of-files