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
/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:

  • D - Data
  • A - Attributes
  • T - Time stamps
  • E - Extended attribute
  • X - Skip alt data streams
/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 defaultretry value of nattempt is 1,000,000 (oneretries millionif retries).n is not specify
/w:<n> Specifies the wait time between retries, in seconds. The default valuewait oftime is 30 seconds if n is 30not (wait time 30 seconds).specify
/log:<logfile> WritesLogs the statusCMD output to the log filefile, (and overwrites the existing log file)file if it exist
/log+:<logfile> WritesLogs the statusCMD output to the log filefile, (and appends the output to the existing log file).file if it exist

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