Use Robocopy to copy only changed files?

Cyberherbalist picture Cyberherbalist · Apr 25, 2014 · Viewed 142k times · Source

I'm trying to find an easy way of deploying only changed files to the webserver for deployment purpose. In times past I've used MSBuild, which could be told to only copy files that were newer than the ones on the target, but I'm in a hurry and don't want to try to figure out the newer version of MSBuild.

Can I use ROBOCOPY for this? There is a list of options for exclusion, which is:

  • /XC :: eXclude Changed files.
  • /XN :: eXclude Newer files.
  • /XO :: eXclude Older files.
  • /XX :: eXclude eXtra files and directories.
  • /XL :: eXclude Lonely files and directories.

What exactly does it mean to exclude? Exclude copying, or exclude overwriting? For example, if I wrote:

ROBOCOPY C:\SourceFolder\ABC.dll D:\DestinationFolder /XO

would this copy only newer files, not files of the same age?

Or is there a better tool to do this?

Answer

Filburt picture Filburt · Apr 26, 2014

To answer all your questions:

Can I use ROBOCOPY for this?

Yes, RC should fit your requirements (simplicity, only copy what needed)


What exactly does it mean to exclude?

It will exclude copying - RC calls it skipping


Would the /XO option copy only newer files, not files of the same age?

Yes, RC will only copy newer files. Files of the same age will be skipped.

(the correct command would be robocopy C:\SourceFolder D:\DestinationFolder ABC.dll /XO)


Maybe in your case using the /MIR option could be useful. In general RC is rather targeted at directories and directory trees than single files.