How to Use Robocopy

Robocopy, also known as Robust File Copy, is a powerful command-line directory replication tool developed by Microsoft. Unlike conventional file copiers like copy and xcopy, Robocopy is specifically designed to efficiently copy directories while preserving their original structure. With Robocopy, you can copy a single directory or recursively copy an entire directory and its subdirectories. It offers advanced features such as automatic resumption of file transfers in case of errors or network disruptions, as well as recovery from interrupted copying. Additionally, selective copying based on new or updated criteria is supported, making it a versatile tool for maintaining identical directory structures on a single computer or across multiple network locations.

<xmp>robocopy <Source> <Destination> [<File> [ ...]] [<Options>]</xm
  1. Source : Specifies the path to the source directory.
  2. Destination : Specifies the path to the destination directory.
  3. File : Specifies the file or files to be copied. You can use wildcard characters (* or ?), if you want.
  4. Options : Specifies options to be used with the robocopy command.

One notable feature of Robocopy is its intelligent handling of file copies. When a file exists both in the source and destination locations, Robocopy will only copy the file if the two versions have different time stamps or sizes. This time-saving approach is particularly advantageous when working with slow network links. Moreover, you can specify that copying should be restarted in case of a failure, further optimizing the process, especially when network links are unreliable.

Robocopy comes pre-installed in Windows operating systems such as Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10, and Windows Server, accessible through the command-line interface. It provides detailed reports of the copy operation and offers real-time progress monitoring of source and destination targets, ensuring comprehensive visibility into the copying process. With its robust and efficient features, Robocopy proves to be an indispensable tool for managing file replication tasks in diverse computing environments.

Robocopy and a Few Examples

How to copy content of a foler to another folder
C:\>robocopy c:\temp D:\backup\mis\dev
Copy a directory
C:\>robocopy c:\temp\newtemp D:\backup\mis\dev\newtemp
Copy subdirectory
C:\>robocopy /S c:\temp D:\backup\mis\dev
Copy the content of folder including empty folder
C:\>robocopy c:\temp D:\backup\mis\dev /E
Copy files larger than specified size
C:\>robocopy C:\temp\newtemp D:\backup\mis\dev /min:4096

The above command copy files from c:\temp\newtemp whose size is larger than 4kb (4096)

Copy files less tha specified size
C:\>robocopy C:\temp\newtemp D:\backup\mis\dev /max:5120

The above command copy files from c:\temp\newtemp whose size is less than 5kb (5120)

Mirror Folder
C:\>robocopy c:\temp D:\backup\mis\dev /MIR

The above command will mirror what is in c:\tempe into D:\backup\mis\dev and purge any files in the D:\backup\mis\dev directory that do not exist in the hope directory.

Use the /MIR switch carefully since it will be deleting files that do not match in the destination directory.

Copy from network
C:\>robocopy \\SERVER\backup\temp D:\backup\mis\dev

The above example would copy any of the files in the temp directory on the network computer (\\SERVER\backup\temp) to the current computer D:\backup\mis\dev directory.

Copy a directory tree
C:\>robocopy C:\temp D:\backup\mis\dev /MIR /dcopy:T
The above command to copy a directory tree along with the source timestamps for folders Delete the source after copying
C:\>robocopy c:\temp\newtemp D:\backup\mis\dev /mov /s

The above command delete the content in the folder c:\temp\newtemp after copying the content to c:\temp\newtemp

Move the files older than specified days
C:\>robocopy c:\temp\newtemp D:\backup\mis\dev /move /minage:10

The above command move files over 10 days old, however the MOVE option will fail if any files are open and locked.

Copy files without overwrite
C:\>robocopy c:\temp D:\backup\mis\dev /E /XC /XN /XO

The above command copy files from source folder to destination folder without overwrite.

  1. /E makes Robocopy recursively copy subdirectories, including empty ones.
  2. /XC excludes existing files with the same timestamp, but different file sizes. Robocopy normally overwrites those.
  3. /XN excludes existing files newer than the copy in the source directory. Robocopy normally overwrites those.
  4. /XO excludes existing files older than the copy in the source directory. Robocopy normally overwrites those.
Hide ROBOCOPY output

How to make robocopy silent in the command line

ROBOCOPY [source] [target] /NFL /NDL /NJH /NJS /nc /ns /np
  1. NFL : No File List - don't log file names.
  2. NDL : No Directory List - don't log directory names.
  3. NJH : No Job Header.
  4. /NJS : No Job Summary.