Robocopy - Compare modified dates of files?

≡放荡痞女 提交于 2019-12-11 02:08:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!