Skip to main content

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. 

Screenshot_2023-11-23_010047.png

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
/sCopies subdirectories and excludes empty directories
/eCopies subdirectories and includes empty directories
/dcopy:<copyflags>

Specifies what to attribute to copy over. The attribute options are:

  • D - Data
  • A - Attributes
  • T - Time stamps
  • E - Extended attribute
  • X - Skip alt data streams
/purgeDeletes destination files and directories that no longer exist in the source
/mirMirrors the destination with the source (equivalent to /e plus /purge)
/movMoves files, and deletes them from the source after they're copied
/moveMoves files and directories, and deletes them from the source after they're copied
/r:<n>Specifies the number of retries on failed copies. The default value of n is 1,000,000 (one million retries).
/w:<n>Specifies the wait time between retries, in seconds. The default value of n is 30 (wait time 30 seconds).
/log:<logfile>Writes the status output to the log file (overwrites the existing log file)
/log+:<logfile>Writes the status output to the log file (appends the output to the existing log file).

Below is what I personally use for my robocopy transfers:

robocopy SOURCE DESTINATION /E /DCOPY:DAT /R:4 /W:10 /LOG:C:\temp\robocopylog.txt


When finish running, you can see the stats of the robocopy from the log file.

Screenshot_2023-11-23_220739.png

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 /LOG:C:\temp\robocopylog.txt

Screenshot_2023-11-23_221313.png

Screenshot_2023-11-23_230926.png