Kenny Bones
Kenny Bones

Reputation: 5129

Robocopy - Compare modified dates of files?

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?

Upvotes: 2

Views: 15324

Answers (2)

aphoria
aphoria

Reputation: 20179

ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR

CORRECTION

ROBOCOPY %SOURCE_DIR% %TARGET_DIR% * /MIR /XO

Upvotes: 6

Rob Levine
Rob Levine

Reputation: 41298

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.

Upvotes: 2

Related Questions