Robocopy is a command-line file transfer utility for Microsoft Windows. Robocopy is functionally more comprehensive than the COPY command and XCOPY, but replaces neither. Created by Kevin Allen and first released as part of the Windows NT 4.0 Resource Kit, it has been a standard feature of Windows since Windows Vista and Windows Server 2008.

Features

Robocopy provides features not found in the built-in Windows COPY and XCOPY commands, including the following:

Robocopy

Recovering from temporary loss of network connectivity (Incomplete files are marked with a date stamp of 1970-01-01 and contain a recovery record so Robocopy knows where to continue from). Detecting and skipping NTFS junction points, which, under certain circumstances, may cause copying failures because of infinite loops (with the /XJ switch). Preserving any combination of the following: file contents, attributes, metadata (e.g., original timestamps), NTFS ACLs (DACLs, SACLs, and owner). For example, it is possible to copy ACLs from one file to another. Before version XP026, however, this capability was limited to files only, not folders.ps). Utilizing the Windows NT "Backup Files and Directories" privilege (SeBackupPrivilege, normally not available to standard user accounts) to bypass NTFS ACLs that would otherwise impede transfer (requires the /B switch). Persistence by default, with a programmable number of automatic retries if a file cannot be copied. The mirror mode, which keeps two directory trees synchronized by also deleting files in the destination that are not present in the source. Skipping files already in the destination folder with identical size and timestamp. Progress indicator Support for paths exceeding 259 characters, up to a theoretical limit of about 32,000 characters. Multithreaded copying (introduced with Windows 7 and Windows Server 2008 R2). Return codes (used in automation).

Robocopy

Compression

Since Windows Server 2019 and Windows 10, Robocopy support SMB compression for transferring files across a network. If the /compression is specified, the destination computer supports SMB compression, and the files being copied are compressible, the operation enjoys significant performance improvements. The SMB compression adds inline whitespace compression to file transfers. Compression is also available with the XCOPY command and Hyper-V live migration with SMB.

Robocopy

Examples of use

Here are some examples of usage, which is not case-sensitive. If more than one option is specified, they must be separated by spaces.

Example 1

Copy directory contents of the source to the destination (including file data, attributes and timestamps), recursively with empty directories (/E):

Robocopy "C:\Directory A" "C:\Directory B" /E

If directory names have non-standard characters, such as spaces, they must be enclosed in double quotes, as is usual in the command line.

Example 2

Copy directory recursively (/E), copy all file information (/COPYALL, equivalent to /COPY:DATSOU, D=Data, A=Attributes, T=Timestamps, S=Security=NTFS ACLs, O=Owner info, U=Auditing info), do not retry locked files (/R:0) (the number of retries on failed copies default value is 1 million), preserve original directories' Timestamps (/DCOPY:T - requires version XP026 or later):

Robocopy C:\A C:\B /COPYALL /E /R:0 /DCOPY:T

Example 3

Mirror A to B, destroying any files in B that are not present in A (/MIR), copy files in resume mode (/Z) in case network connection is lost:

Robocopy C:\A \\backupserver\B /MIR /Z

For the full reference, see the Microsoft TechNet Robocopy page.

Syntactic focus on copying folders

Robocopy syntax is markedly different from its predecessors (copy and xcopy), in that it accepts only folder names, without trailing backslash, as its source and destination arguments. File names and wildcard characters (such as * and ?) are not valid as source or destination arguments; files may be selected or excluded using the optional "file" filtering argument (which supports wildcards) along with various other options.

For example, to copy two files from folder c:\bar to c:\baz, the following syntax is used:

robocopy c:\bar c:\baz file1.txt file2.db

And to copy all PDF files from c:\bar to c:\baz:

robocopy c:\bar c:\baz *.pdf

The files named are copied only from the folder selected for copying; fully qualified path names are not supported.