sync to a target directory from the command line (ROBOCOPY)

for reference, here is how to update a TARGET directory, so that it mirrors the SOURCE directory, from the Windows command line.

robocopy is built in to Windows (XP, Vista, 7) and is a decent file copier (better than say copy or xcopy, especially for large files, or copying over a  network connection)

WARNING: robocopy is a powerful tool, and should be used with care.  in particular, the /MIR option is destructive and will remove any files from target directory, that are not in the source directory !

Please read the help instructions before using robocopy.

To see the help instructions, from the Command Line type:

robocopy /?

here is how to copy from a source directory to a target directory: (will overwrite files without checking the modified timestamp!)

 robocopy /E /ZB /ETA sourceDir destDir

SAFE COPY:
here is how to copy only files that are not already in destination, OR else are newer:

 robocopy /E /ZB /XO /ETA /DST /FFT sourceDir destDir

alternative: use xcopy (simpler but less reliable for large files or slow network connection etc.)

 xcopy sourceDir destDir /D /E /C /I /F /H /R /Y /EXCLUDE:excluded_files.txt


SAFE MOVE:
and here is how to MOVE the files and directories that are new or newer, from a source directory to a target directory:

 robocopy /E /ZB /XO /ETA /DST /FFT /MOV sourceDir destDir

Comments