RoboCopy
If you are familiar with rsync on Linux, you will appreciate this Windows command line tool - robocopy.
Robocopy stands for “Robust File Copy.” It is a built-in Windows utility tool for transfering files from one location to another.
Robocopy Syntax and Flags
The basic syntax for robocopy is as follow:
robocopy SOURCE DESTINATION
There are also some flags you can use to fine tune the file transfer. Some are the most commonly used flags are:
Flags |
Description |
/s | Copies subdirectories and excludes empty directories |
/e | Copies subdirectories and includes empty directories |
/dcopy:<copyflags> |
Specifies what to attribute to copy over. The attribute options are:
|
/purge | Deletes destination files and directories that no longer exist in the source |
/mir | Mirrors the destination with the source (equivalent to /e plus /purge) |
/mov | Moves files, and deletes them from the source after they're copied |
/move | Moves files and directories, and deletes them from the source after they're copied |
/r:<n> | Specifies the number of retries on failed copies. The retry attempt is 1,000,000 retries if n is not specify |
/w:<n> | Specifies the wait time between retries, in seconds. The default wait time is 30 seconds if n is not specify |
/log:<logfile> | Logs the CMD output to the log file, and overwrites the existing log file if it exist |
/log+:<logfile> | Logs the CMD output to the log file, and appends to the existing log file if it exist |
/tee |
When used with /log, shows CMD output within the terminal in addition to saving it to a log file. |
Below is what I personally use for my robocopy transfers:
robocopy SOURCE DESTINATION /E /DCOPY:DAT /R:4 /W:10 /tee /LOG:C:\temp\robocopylog.txt
The /tee option will show you robocopy status, while also allowing the output to be save to a log file.
Occasionally, I also use the /MIR option to keep the destination in sync with the source. This will copy over any difference from the source folder to the destination folder, and then delete from the destination folder that is no longer in the source folder.
robocopy SOURCE DESTINATION /MIR /E /DCOPY:DAT /R:4 /W:10 /tee /LOG:C:\temp\robocopylog.txt