Programming Field

Robocopy (Robust File Copy for Windows) - DOS/Command Prompt Reference

[Windows Vista or later (*)] Performs the copying of files/directories. It allows specifying more advanced options than traditional commands like Copy or Xcopy.

* Robocopy is installed by default in Windows Vista and later versions, but in earlier Windows versions, it may be included in the Resource Kit (included in the Resource Kit for NT 4.0/2000/XP and Windows Server 2003).

Usage

Usage of Robocopy

Robocopy is used by specifying the path and filename to be copied, followed by specifying options. The syntax is as follows:

robocopy[.exe] <source-path> <dest-path> [<files>...] [options]

Specify the source directory name in <source-path>, the destination directory name in <dest-path>, and then specify the filename in the source directory that you want to copy (wildcards are allowed, see wildcards). For example, the command would be like the following:

robocopy C:\MyDocs D:\Backup\MyDocs *.*

* Note that if not specifying <files>, the default is to use ‘*.*’ so if you're not narrowing it down by filename, you can omit ‘*.*’.

An important aspect of using Robocopy is the ability to choose ‘which files to copy/not copy’ using its extensive options. It allows control over behaviors such as the information to be copied, copy speed, and more. For example, specifying ‘/XO’ ensures that when there is a file with the same name in both the source and destination, it will not be copied if the file in the source is older (excluding older files). Specifying ‘/MT:2’ sets the number of threads used for copying to 2 (default is 8, so this reduces the number of threads). Specifically, there are various types of options, including the following:

Details are introduced in the later section ‘Options’, but if you're not familiar, it's recommended to assemble while trying with temporary directories. (Please refer to samples as well.)

Options

* If multiple options of the same type are specified, the option specified later will be used. (Example: If ‘/COPYALL /COPY:AS’ is specified, ‘/COPY:AS’ will be used.)

Option list

Base parameters

<source-path>
Specifies the directory name where the source files/directories are located.
* When describing in a job file, you can use the option ‘/SD’ to specify ‘/SD:<source-path>’.
* If <source-path> is specified in the job file (or specified with /SD), you cannot specify <source-path> on the command line.
<dest-path>
Specifies the directory name where the files/directories will be copied to. Even if there are no files to copy or the number of files to copy is 0, a new directory will be created (and its parent directories), if they do not exist.
* When describing in a job file, you can use the option ‘/DD’ to specify ‘/DD:<dest-path>’.
* If <dest-path> is specified in the job file (or specified with /DD), you cannot specify <dest-path> on the command line.
<files>
Specifies the names of files/directories existing in <source-path>. If specifying multiple, the names must be separated by spaces (if a file name contains spaces, enclose it in double quotes " "). You cannot use a specification like ‘dir\file’; you must always refer to names directly under <source-path>. Also, you cannot specify ‘.’ or ‘..’. Wildcards can be used here.
* If you want to copy the <source-path> directory itself, specify its parent directory in <source-path> and specify the relevant directory name in <files>. Copying the entire root directory (such as C:) or an entire shared folder (like \somepc1\share) as a directory is not possible, so to copy everything, you need to use wildcards or similar methods to copy all the files within.
If omitting <files>, the process is performed as if ‘*.*’ is specified.
* You can also specify file names after each option (strings that do not begin with "/" and are the third and subsequent ones are all interpreted as file names).
* You can use ‘/IF’ option and specify it as ‘/IF <files>...’ when using it. This is used when describing in a job file.

Option details

Copying options
Specifying directory hierarchy
/S
If <files> includes directories, Robocopy also copies subdirectories, but it does not copy empty directories. This is equivalent to the ‘/S’ option in Xcopy.
/E
If <files> includes directories, Robocopy also copies subdirectories, including empty directories. If both /S and /E are specified simultaneously, the option that appears later takes precedence (in the case of ‘/E /S’, empty directories will not be copied). This is nearly identical to the Xcopy ‘/E’ option, but please be cautious about the order of option specification.
* If both /S and /E are not specified, directories will not be copied even if <files> includes directories.
/LEV:n
Specifies the depth of subdirectory levels if /S or /E is specified. Specifies n with a numerical value indicating the hierarchy. ‘1’ is considered the hierarchy of the source directory itself. Specifying ‘1’ means no subdirectories, while specifying ‘2’ explores up to one level of subdirectories. If you omit ‘/LEV:n’ or specify ‘0’ for n, there will be no restrictions.
Specifying information to be copied, file deletion (move/mirror) options
/COPY:flags
Selects information to copy. For flags, specify which information to copy by combining the following ‘characters’ in the list. For example, if you want to copy ‘Attributes’ and ‘Timestamp’, you can specify ‘AT’; if you only want to copy security information, you can specify ‘S’. If not specified, it is treated as if ‘DAT’ were specified.
CharMeaningDescription
DFile dataCopies the data written to the file. If not specified, the copy is skipped, and the file is not created if the file does not exist at the destination (however, if /CREATE is specified, it will be created with 0 bytes even without /COPY:D. In this case, if there are specifications in flags, attributes and other information will be copied).
AAttributeCopies basic attribute information such as ‘Read-only’ and ‘Archive’ attribute, as well as encryption status. However, if /CREATE is specified, encryption status is not copied.
TTimestampCopies timestamp information such as ‘Creation time’ and ‘Last modified time’. If not specified or if the modification time matches, it is generally not copied. However, if ‘D’ is specified, it will be copied (it will not be copied if the content is the same and the modification time matches).
SSecurity informationCopies user-specific access control information and etc. Both the source and destination must support common security information for the file system (such as NTFS).
OOwnership informationCopies ownership information of files/directories. Both the source and destination must support common ownership information for the file system (such as NTFS).
UAudit informationCopies audit settings for files/directories. Both the source and destination must support audit settings for the file system (such as NTFS). Additionally, when using this option, administrator privileges (Security privilege; SeSecurityPrivilege) are required.
XSkip alternate data stream[Windows 10 version ??? or later] Does not copy alternate data streams. If this option is not specified, alternate data streams are copied by default. (However, using only ‘/COPY:X’ would result in no information being copied, so it is necessary to combine it with other options such as ‘/COPY:DATX’.)
* Regarding encryption status, even if ‘A’ is specified, it will not be copied if there are no changes in the data. Also, if the source is non-encrypted and the destination is encrypted, the encryption status of the destination will not be removed.
/SEC
Copies not only file data and basic information but also security information. This is equivalent to specifying ‘/COPY:DATS’.
/COPYALL
Copies all file data and all information related to the file. This is equivalent to specifying ‘/COPY:DATSOU’.
/NOCOPY
Does not perform the copy (Copy no file info). When combined with the ‘/PURGE’ option, it allows only the deletion of files that do not exist in the source.
/DCOPY:flags
Specifies the information to be copied along with the directory during the copy. In flags, combine the following ‘characters’ from the list to specify which information to copy.
CharMeaningDescription
TTimestampCopies the creation time of the directory.
DData[Windows 8 or later] Copies data (default option). If the D option is specified, alternate data streams for directories are copied (they are not copied if not specified).
AAttribute[Windows 8 or later] Copies attributes (default option).
EExtended attribute[Windows 10 version ??? or later] Copies extended attributes (EA). (Extended attributes are not typically accessible through normal means, but they may be readable and writable via Linux commands over the network in some cases.)
XSkip alternate data stream[Windows 10 version ??? or later] Does not copy data (cancels the effect of D). If specifying ‘T’ or ‘A’, it is not necessary to use ‘X’ if ‘D’ is not specified. However, if you do not want to specify other options, you can use ‘/DCOPY:X’.
* It cannot be used with older versions of the Resource Kit Robocopy.
* Even without the ‘A’ specification, attributes such as read-only and hidden files are copied. It is unknown which attributes are specifically controlled by ‘A’.
* Even if the copy fails when specifying ‘E’, the copy process will continue without interruption.
* If ‘E’ is not explicitly specified, even when using ‘/COPYALL’, extended attributes will not be copied.
/NODCOPY
[Windows 8 or later] Does not copy information such as directory attributes (Copy no directory info). If not specified, ‘/DCOPY:DA’ is used by default, so this option is used to override its effect. Also, when using this option, attributes such as ‘hidden files’ will not be copied.
/SECFIX
Fixes the security information (access rights, etc.) of the destination files with the source, including files that were skipped. The copy specification must include ‘S’ (include ‘S’ in options such as /COPY:S or /SEC).
* It cannot be used with older versions of the Resource Kit Robocopy.
/TIMFIX
Fixes the file time (mainly creation time) of the destination files with the source, including files that were skipped. If the file in the source and destination is not the ‘same content and same modification time’, no modification is made. Unlike /COPY:T, which does not copy creation time when the file content and modification time match, this option allows copying (fixing) the creation time in such cases.
* It cannot be used with older versions of the Resource Kit Robocopy.
/PURGE
Removes files and directories in the destination that do not exist in the source. If /E is not specified (if /MIR is not specified), only the directories directly under the destination are checked, and the files and subdirectories inside them are not checked.
/MIR
Performs mirroring, making the file count and data in the source and destination the same. This is equivalent to specifying ‘/E /PURGE’.
/MOV
Moves files (the source files are deleted after copying).
* Files for which no copy operation was performed (such as when the source and destination are identical) are not deleted. Even if there are specifications that prevent data copying, such as ‘/COPY:AT’, if the attributes do not match, the copy will be performed, and in that case, the source will be deleted.
/MOVE
Moves files and directories (the source files and directories are deleted after copying).
/A+:<attrs>
Adds attributes to the destination files after copying. <attrs> will be one or a combination of the following characters to represent the attributes.
CharMeaning
RRead-only
AArchive
SSystem file
HHidden file
CCompressed file (for NTFS etc.)
NNon-indexed file (* In Attrib and etc. this attribute is represented as ‘I’. %~aX does not display this attribute.)
EEncrypted file
TTemporary file (* This attribute cannot be set with Attrib, but it can be verified with ‘T’ in the ‘Details’ tab of the file properties in Explorer or by using the value obtained with %~aX.)
* The ‘Temporary file attribute’ (T) stores data in memory as much as possible during file operations, and writes the data when it can no longer be stored or when the file operation finishes without being deleted. Files with the temporary file attribute are expected to be deleted after use, so adding this attribute indiscriminately can result in data loss or impact performance.
* Robocopy tries to add attributes to the destination directory, so some attributes (such as T) may not be set, resulting in an error.
* C and E cannot be used with older versions of the Resource Kit Robocopy.
/A-:<attrs>
Removes the attributes from the destination files after copying. <attrs> will be the characters from the above list, corresponding to the attributes you want to delete.
[Windows 11 ???? or later] Specific for /A-, you can also specify ‘O’ (Offline attribute) in <attrs>
/CREATE
Creates only the files without copying the contents (does not copy data even if /COPY:D is present). If /S or /E is specified, the corresponding directories are also created. If the destination already exists, it does not overwrite the data with 0 bytes but only copies information such as date and attributes (if specified by options).
/SL
[Windows Vista SP1 or later] If there is a symbolic link in the source, it copies the symbolic link itself, not the target. This is effective for symbolic links to directories only when /S or /E is specified.
* Copying symbolic links requires administrator privileges (Symbolic Link Creation privilege; SeCreateSymbolicLinkPrivilege).
* The /SL option does not affect directories created as junction points instead of symbolic links, and if /E is present, they are created at the destination as directories, not as junction points. [Windows 10] To copy as a junction point, use /SJ option.
/SJ
[Windows 10 2004 or 17763.1432? later] Copies the junction point itself, not the target, if there is a junction point in the source. This is effective only when /S or /E is specified.
Specifying copy modes (processing options)
/Z
Copies in restartable mode. If a communication failure or similar issue occurs and the copy fails, you can resume copying by using the same file names.
/B
Copies in backup mode. If the current user has backup and restore privileges (SeBackupPrivilege, SeRestorePrivilege), The copy operation can be performed regardless of ownership or security.
* Administrator privileges or a user with backup and restore privileges are required. For details, please see detail's ‘About privileges’.
/ZB
Copies in restartable mode, and if an access denied error occurs, uses backup mode.
* Administrator privileges or a user with backup and restore privileges are required. For details, please see detail's ‘About privileges’.
/J
[Windows 8 or later] Copies in unbuffered I/O mode. This mode does not use temporary buffers for file I/O, which can improve the copying speed for large files. However, if the copy is interrupted, it may result in unexpected states.
/EFSRAW
Copies encrypted files in EFS RAW mode. In EFS RAW mode, Robocopy copies encrypted files as they are, without decrypting or encrypting them. This allows copying operations to be performed even without the decryption key (even if the contents of the file are not known), as long as there are backup-like permissions.
* This option needs to be run by a user with access rights to the relevant files, administrator privileges, or backup privileges.
* It cannot be used with the Resource Kit Robocopy.
/FAT
Creates destination files using only the ‘short file name’ (8.3 format FAT file name).
/256
Turns off support for path names longer than 256 characters. When this switch is specified, attempting to copy a file with a path that is too long results in a file not found error.
/MON:n
Starts monitoring after the copy operation (Monitor source). If Robocopy detects n changes in the source, it performs the copy again and continues monitoring. n will be a numerical value. ‘Changes’ include not only changes in file content but also changes in modification timestamps and attributes. Monitoring is done by checking files each time at intervals specified by /MOT:m (1-minute intervals by default). Even if there are changes and reversals within that interval, it counts as two changes (e.g. setting and then removing the read-only attribute counts as two changes). To end monitoring, enter Ctrl+C.
* Normally, changes in file content also result in a modification timestamp change, counting as two changes (unless intentionally keeping the modification timestamp the same).
/MOT:m
Starts monitoring after the copy operation, checks at intervals of m minutes, and if Robocopy detects any changes at least once, it performs the copy again and continues monitoring (Monnitor source; run again in a minute time). If /MON is specified, it performs the copy again when the specified number of accumulated changes is reached. Please refer to the description of /MON for details about monitoring content.
/RH:hhmm-hhmm
Restricts the time frame during which the copy operation is performed (Run hours). hhmm will be the time in 24-hour format based on the local system time (e.g. ‘1430’ for 2:30 PM). File copying occurs only during the specified time, and at other times, it waits for execution. If the time range is reversed (e.g., /RH:1234-1212), the smaller time is treated as the time of the next day.
/PF
Checks the restriction for each file instead of the path (parent directory) when restricting copying by time with /RH (Per file). This means that if there is a file that takes a long time to copy, the copying of the next file may be interrupted if it extends beyond the specified time frame.
/IPG:n
Specifies the Interpacket Gap (IPG). n will be the time in milliseconds. Robocopy performs data copying in approximately 64 KiB units, and when it reads and copies a unit of data, it waits for the specified time with this option. This option is used for purposes such as preventing network congestion during network-based copying.
/MT:n
[Windows 7 or later] Performs copying with multiple threads. n will be the number of threads to create. Increasing the number of threads allows parallel processing, and in some environments, it can significantly speed up the copying process. Additionally, using /LOG option to write log output to a file may further enhance performance.
/MT option cannot be used in conjunction with /EFSRAW or /IPG. In other cases, if /MT is not specified, Robocopy performs parallel processing with 8 threads by default.
/NOOFFLOAD
[Windows 8 or later] Does not perform copying using Offloaded Data Transfer (ODX). If this option is not used, optimized copying may be done using Offloaded Data Transfer, so using /NOOFFLOAD may result in reduced performance.
/COMPRESS
[Windows 10 2004 or 17763.1432? later] Performs copying using SMB Compression if available. SMB Compression allows data compression during network-based copy operations, helping to conserve bandwidth and potentially improve transfer speeds.
* This feature requires the destination to support SMB Compression.
/SPARSE
[Windows 11 22H2? or later] Preserves the sparse status of sparse files during the copy operation. If not specifying this option, copying a sparse file will result in a non-sparse file at the destination.
* It seems that in some versions of Windows 11 that are not the latest, attempting to copy a file with sparse ranges using the /SPARSE option may result in the copy operation stopping prematurely. (However, in at least Windows 11 ver. 10.0.22621.2506, the copy operation works correctly.)
Throttling options
/IoMaxSize:size
[Windows 11 or later] Sets the size limit per cycle (read and write) during the copy operation. size can be specified in bytes or using units such as ‘K’ (kilobytes), ‘M’ (megabytes), or ‘G’ (gigabytes). For example, if you want to set a limit of 2 gigabytes, you can use ‘/iomaxsize:2G’. This ensures that each cycle of the copy operation does not exceed the specified size limit. (see also Details)
/IoRate:size
[Windows 11 or later] Sets the maximum copy speed, expressed as the size limit per second. size can be specified in bytes or using units such as ‘K’ (kilobytes), ‘M’ (megabytes), or ‘G’ (gigabytes). For example, if you want to set a limit of 1 MiB/s (1 megabyte per second), you can use ‘/iorate:1M’. This ensures that the copy operation does not exceed the specified speed limit. (see also Details)
/Threshold:size
[Windows 11 or later] Specifies a lower limit for the file size to which the restrictions of /IoMaxSize or /IoRate apply. By default, the restrictions apply to all files, but when /Threshold is specified, the limitations will not apply to files below the specified size. size can be specified in bytes or using units such as ‘K’ (kilobytes), ‘M’ (megabytes), or ‘G’ (gigabytes). For example, if you want to set a lower limit of 2 gigabytes, you can use ‘/threshold:2G’.
File select options
Selection/exclusion based on attributes
/A
Selects only files with the Archive attribute set. It is similar to /A option in Xcopy.
/M
Selects only files with the Archive attribute set and removes the Archive attribute after copying. It is similar to /M option in Xcopy.
/IA:<attrs>
Includes only files with the specified attributes. <attrs> can include the same characters as the ‘/A+’ option, which are ‘RASHCNET’, and it can also include ‘O’ (the offline file attribute).
* The offline file attribute is an attribute that cannot be set using Robocopy or Attrib, but you can check for the ‘O’ attribute in the file properties' ‘Details’ tab in Windows Explorer or by using %~aX in the command line. Additionally, in Windows Explorer, files with the offline attribute may have an icon with an ‘X’ mark.
/XA:<attrs>
Excludes files with specified attributes. <attrs> can includes the same attribute letters ‘RASHCNETO’ as the /IA option.
Exclusion based on name
/XF <file>...
Excludes specified files from the copy. <file> will be the file names to be excluded (absolute paths and wildcards are allowed, but wildcards and absolute paths cannot be combined). Multiple files can be specified, separated by spaces.
* After /XF option, any string not starting with ‘/’ until the /XD option is encountered will be treated as a string specified in <file> for /XF option.
/XD <directory>...
Excludes specified directories and their files. <directory> will be the directory name to be excluded (absolute paths and wildcards are allowed, but wildcards and absolute paths cannot be combined). Multiple directory names can be specified, separated by spaces.
* After /XD option, any string not starting with ‘/’ until the /XF option is encountered will be treated as a string specified in <directory> for /XD option.
Selection/exclusion based on differences
/XC
Excludes files that have changes by comparing the source and destination for copying.
* ‘Files that have changes’ refer to files where the file timestamps (modification times) are the same between the source and destination, but the contents are different. Typically, when you edit a file, the file timestamp (modification date) also changes, so it is rare to have files excluded by this option (you can create such files using ‘/COPY:T’).
/XN
Excludes files where the source is newer when comparing the source and destination for copying.
/XO
Excludes files where the source is older when comparing the source and destination for copying.
/XX
Excludes files and directories that exist only in the destination (those are called extra files and directories). When specified with /PURGE, its effect is almost nullified.
/XL
Excludes files and directories that exist only in the source (those are called lonely files and directories). This is useful when you want to perform updates only on files that exist in both the source and destination.
/IS
Includes files that match between the source and destination (i.e. those are the same). Without specifying /IS, identical files will be skipped. This option does not exclude files that do not match.
* ‘Matching files’ refer to files with identical content and modification timestamps between the source and destination. Specifying /IS does not change the files targeted for fixing by /TIMFIX.
/IT
Includes files with minor changes (those are called tweaked files). ‘Minor changes’ refer to changes in file attributes, for example. Usually, changes in file attributes do not categorize a file as having changes. If the contents and modification timestamps of the files match, they may be excluded from the copy target even if the attributes are different. However, specifying the /IT option allows you to align file attributes.
* ‘Differences in encryption status’ are not included in the targets covered by /IT.
/IM
[Windows 10 2004 or 17763.1432? later] Includes files with different ‘internal modification timestamps’ when comparing the source and destination (i.e. include ‘Modified’ files). ‘Internal modification timestamp’ is different from the regular modification timestamp and is primarily updated when attributes such as security information (information within the MFT entry) are modified, rather than the data being rewritten, especially in the NTFS file system (MFT entry's modification timestamp). For example, in the case of a file where only security information is modified, it will not be considered ‘included’ unless you use the /IS option (even with the /IT option), but by using the /IM option, it will be treated as ‘included’ because the internal modification timestamp is updated.
Note that if you choose to treat security information to be copied (by including S O U in the /COPY option or using the /SEC option), the /IM option is automatically specified.
* This option is effective only when both the source and destination support internal modification timestamps. For example, it is effective when both the source and destination are NTFS.
Selection/exclusion based on date
/MAX:n
Excludes files from the copy operation if they are larger than the specified number of bytes (Maximum file size). n will be the size boundary in bytes.
/MIN:n
Excludes files from the copy operation if they are smaller than the specified number of bytes (Minimum file size). n will be the size boundary in bytes.
/MAXAGE:n
Excludes files from the copy operation if their modification timestamp is older than the specified number of days or date. (Maximum file age: Specifies the maximum elapsed period to include files in the target.) n will be the number of days to go back in the past or the actual date in the ‘YYYYMMDD’ format (if ‘3’ is specified, Robocopy sets the boundary as 3 days ago).
/MINAGE:n
Excludes files from the copy operation if their modification timestamp is newer than the specified number of days or date. (Minimum file age: Specifies the minimum elapsed period to include files in the target.) n will be the number of days to go back in the past or the actual date in the ‘YYYYMMDD’ format.
/MAXLAD:n
Excludes files from the copy operation if there has been no access to the files since the specified number of days or date. (Maximum last access date: Specifies the initial access timestamp to include files in the target.) n will be the number of days to go back in the past or the actual date in the ‘YYYYMMDD’ format (if ‘3’ is specified, Robocopy checks whether there has been access in the period from 3 days ago to the present and excludes those without access).
/MINLAD:n
Excludes files from the copy operation if there has been access to the files since the specified number of days or date (Minimum last access date: Specifies the final access timestamp to include files in the target.) n will be the number of days to go back in the past or the actual date in the ‘YYYYMMDD’ format.
/FFT
Performs date and time comparisons using FAT file times (file timestamps in the FAT file system). FAT file times have a time accuracy of 2 seconds, and differences less than that are treated as the same timestamp.
/DST
Performs daylight saving time adjustment.
* It cannot be used with older versions of the Resource Kit Robocopy.
/XJ
Excludes junction points and symbolic links. By default, files and directories that are ‘junctions’ or ‘symbolic links’ (only directories for ‘junctions’) are included in the copy target. Even if /SL or /SJ is specified, if /XJ is specified, the copy operation will not be performed for those files/directories.
/XJD
Excludes junction points and symbolic links for directories. Even if /SL or /SJ is specified, if /XJD is present, the copy operation for the respective directory will not be performed (if /XJ and /XJF are not specified, symbolic links for files will be copied).
* It cannot be used with older versions of the Resource Kit Robocopy.
/XJF
Excludes symbolic links (junction points) for files. Even if /SL is specified, if /XJF is specified, the copy operation for the respective file will not be performed (if /XJ and /XJD are not specified, junction points and symbolic links for directories will be copied).
* Junction points generally do not exist for files; therefore, this pertains to excluding symbolic links for files.
* It cannot be used with older versions of the Resource Kit Robocopy.
Retry options
/R:n
Specifies the number of retry attempts in case of copy failure. n will be the number of retries as a numerical value. If not specified, the value stored in the registry (saved with /REG below) will be used, or if that value doesn't exist, the default value of ‘1,000,000’ (1 million times) will be used.
/W:n
Specifies the waiting time, in seconds, before retrying in case of copy failure. n will be the waiting time as a numerical value in seconds. If not specified, the value stored in the registry (saved with /REG below) will be used, or if that value doesn't exist, the default value of ‘30’ (30 seconds) will be used.
/REG
Saves the values specified with /R and /W to the registry. The save location is ‘HKEY_CURRENT_USER\Software\Microsoft\ResKit\Robocopy’, where ‘RetryMax’ stores the retry count, and ‘WaitTime’ stores the wait time in milliseconds.
/TBD
In case of the "‘he network name cannot be found’ error (system error value: 67), Robocopy will retry until the shared name (network name) is defined (To Be Defined) instead of terminate immediately as an ‘undefined error’. The number of retries and wait time will follow the settings of /R and /W.
※ The ‘Network path not found’ error (computer not found error) with a system error value of 53 is not covered by this and is excluded.
/LFSM[:size]
[Windows 10 2004 or 17763.1432? later] Enables ‘Low Free Space Mode’. In this mode, if the available space on the destination volume falls below a specified size (threshold), the copy operation is paused and retried according to the options /R and /W.
The threshold is specified in ‘/LFSM:size’ option, where ‘size’ is a numerical value with units ‘K’ (kilobytes), ‘M’ (megabytes), or ‘G’ (gigabytes). For example, if you want to set a lower limit of 2 gigabytes, you would specify ‘/LFSM:2G’.
If you simply specify ‘/LFSM’ without specifying a size, it will use a threshold equivalent to 10% of the ‘available space on the destination volume’ (not 10% of the ‘total capacity of the destination volume’).
* Since the copy process is not performed byte by byte, it is rare for the operation to pause exactly at the threshold. In most cases, it will pause when the available space is somewhat below the threshold.
Log options
* The following ‘output (to log)’ will be output to the console (standard output) if there is no specified output to a file.
/L
Outputs a list of files when copying, adding, or deleting occurs, but does not perform the actual operations. This is useful when you want to confirm what file operations would occur based on the options specified in Robocopy.
/X
Outputs a list of files that are not selected (output extra files). If files are specified in ‘<files>...’, typically only the files that were copied (or moved, etc.) are logged. However, by specifying the /X option, a list of other files (EXTRA Files) will also be output.
* The term ‘files not selected’ is unrelated to files excluded by the ‘File select options’.
/V
Outputs a list of skipped files (verbose). This includes files that were not copied because the source and destination were the same, as well as files excluded by the ‘File select options’ and other such cases.
/TS
Includes the file's modification timestamp as a timestamp in the log when outputting a list of files.
* Timestamps are output in UTC time.
/FP
Includes the full path of the file in the log when outputting a list of files.
/BYTES
Includes the size of the file in bytes in the log when outputting a list of files. By default, values exceeding a certain threshold are output in units such as ‘k’ (KiB) or‘"m’ (MiB), but specifying /BYTES will output the value in bytes without unit separators.
/NS
Does not include file sizes in the log (No size). If /BYTES is specified, this option is ignored.
/NC
Does not include file classes in the log (No file classes). ‘File classes’ refer to categories such as ‘Newer’, ‘Older’, ‘EXTRA files’, etc., and by default, these categories are included in the log.
/NFL
Does not include the file list in the log (No file list).
/NDL
Does not include the directory list in the log (No directory list).
※ When /NDL is specified, file names will be output as full paths, similar to when /FP is specified.
/NJH
Does not output the job header (No job header). The ‘job header’ includes the Robocopy program name, start time, and various option displays.
/NJS
Does not output the job summary (No job summary). The ‘job summary’ includes a list of the total number of files and directories, such as copied, skipped, and extra files and directories, along with the end time.
/NP
Does not display progress information, such as the percentage indicating how much has been copied (No progress).
/ETA
Outputs the estimated time of arrival for copied files for the second and subsequent files.
* The estimated time of arrival tends to be significantly later than the actual time. Additionally, if the value of /IPG is increased, the estimated time of arrival will also be delayed accordingly.
/LOG:<log-file>
Outputs the log to a file specified by <log-file> instead of the console (standard output). During output, the contents of the file are overwritten (cleared).
/LOG+:<log-file>
Outputs the log to a file specified by <log-file> instead of the console (standard output). Unlike /LOG, the file's contents are preserved during output, and the log is appended.
* When appending, the EOF character (\x1A) at the end of <log-file> will not be removed.
/UNILOG:<log-file>
Except for outputting the log in Unicode (UTF-16), it is the same as /LOG. The log will have a BOM added.
* [Until Windows 7?] As of February 2015, on Windows 7, this option only adds a BOM and outputs the content in the system code page, not functioning correctly (it works correctly on Windows 8.1). This behavior persists even if you switch the code page using Chcp.
* It cannot be used with older versions of the Resource Kit Robocopy.
/UNILOG+:<log-file>
Except for outputting the log in Unicode (UTF-16), it is the same as /LOG+.
* [Until Windows 7?] As of February 2015, on Windows 7, this option only adds a BOM and outputs the content in the system code page, not functioning correctly (it works correctly on Windows 8.1). This behavior persists even if you switch the code page using Chcp.
* If <log-file> does not have a Unicode BOM, it will be output in the system code page. Additionally, if it has a UTF-8 BOM, it will be output in UTF-8.
* It cannot be used with older versions of the Resource Kit Robocopy.
/UNICODE
Outputs in Unicode (UTF-16).
* As of November 2023, it seems that this option does not work correctly on Windows 7, Windows 8.1, Windows 10, or Windows 11. (It is recommended to use /UNILOG instead.)
* It cannot be used with older versions of the Resource Kit Robocopy.
/TEE
Even when outputting the log to a file using /LOG or /UNILOG, log output to the console (standard output) is also performed. This is similar to using the tee command in Linux.
Job-related options
/JOB:<job-file>
Specifies the job file where options are described (see details on ‘About job file’ below). The <job-file> must be a file with the extension ‘RCJ’. Robocopy reads additional options specified in the job file and processes them in addition to the options specified on the command line (after /JOB).
* Specifying a file with an extension other than ‘RCJ’ will result in an error.
* JOB cannot be specified more than twice (you cannot load more than two job files from the command line). However, it is possible to write only one ‘/JOB’ in a job file, and from within that job file, you can load options from another job file.
* If there are overlapping options between those specified before /JOB and the options inside the job file, the options inside the job file take precedence. This is similar to how options take precedence when there are duplicates on the command line.
/SAVE:<job-file>
Specifies the job file to save options (explained later). <job-file> must be a file with the extension ‘RCJ’. If /QUIT is not specified, the command is executed simultaneously with the saving of options.
* If a file with an extension other than ‘RCJ’ is specified, the extension ‘RCJ’ will be appended when saving.
* If you use both /JOB and /SAVE, the content of the job file specified with /JOB and the options specified on the command line will be merged and output.
* The options saved with /SAVE are only those specified before /SAVE, including options from job files. If there are options after /SAVE, they will not be saved in the job file.
/QUIT
Exits without executing the command. When combined with /SAVE, it creates a job file; when combined with /JOB, it allows you to confirm the options described in the job file.
* It is possible to use /QUIT without combining it with /SAVE or /JOB.
* ‘/QUIT’ itself is not saved in the job file.
/NOSD
Specifies that no source directory is provided. This is used when the source is not specified in the job file. If ‘/NOSD’ exists in the job file, you need to specify the source directory from the command line.
* When combining /SAVE and /QUIT to create a job file, there is no need to specify /NOSD.
/NODD
Specifies that no destination directory is provided. This is used when the destination is not specified in the job file. If ‘/NODD’ exists in the job file, you need to specify the destination directory from the command line.
* When combining /SAVE and /QUIT to create a job file, there is no need to specify /NODD.
/IF <file>...
Includes the file following ‘/IF’ as part of the files to be copied. This is used when describing the contents equivalent to <files>...’ in the command line in the job file (it is also possible to use "/IF" on the command line).

Details

About Robocopy

Robocopy is a useful program for executing scheduled tasks such as copying (or mirroring) files and directories. It provides detailed options for file attribute manipulation, retry control, log output, and more.

While Xcopy allows for relatively detailed copy operations, there are primarily the following operations that cannot be achieved with Xcopy.

  • Selection and determination of copy targets based on file attributes, timestamps, etc.
  • Deletion of files that exist only in the destination (mirroring).
  • Loading options from an external file (job file).

* While Robocopy allows copying a single file, it cannot perform the copy of a single file where the source and destination have different filenames (for such cases, you would use Copy or Xcopy).

Selecting files to copy

Robocopy provides the ability to specify files directly from options and includes features for selecting files that meet specific conditions. The types of conditions and the corresponding options are as follows.

Type of conditionOption to ‘include’Option to ‘exclude’/th>
File name /IFSelect only files that match the pattern/XFExclude files that match the pattern
(specify file name directly) /XDExclude by (parent) directory name
Date / time (none)/XNExclude if the source is newer
/XOExclude if the source is older
/MAXAGEExclude files with an older last update
/MINAGEExclude files with an newer last update
/MAXLADExclude files that have not been accessed since the specified date
/MINLADExclude files that have been accessed since the specified date
File attribute /IASelect only files with the specified attributes/XAExclude files with the specified attributes
/ITInclude files with attribute changes only
/ASelect only files with the archive attribute
/MSelect only files with the archive attribute (remove the attribute after processing)
Link (none)/XJExclude junction points and symbolic links
/XJDExclude junction points and symbolic links for directories
/XJFExclude symbolic links for files
Size (none)/MAXExclude files exceeding a certain size
/MINExclude files that are below a certain size
Miscellaneous /ISInclude files that ‘match’/XXExclude files that exist only in the destination
/XLExclude files that exist only in the source
/XCExclude files with different content

Confirming copy operation

The above file selection options can be combined in multiple ways. To confirm which files will be selected based on the combinations, use ‘/L’. Since the command line (or job file) can become complex when combining multiple options, it is recommended to use /L for confirmation.

Note that ‘/QUIT’ only outputs options to the screen, but it can also be used for confirmation when combining the command line and job file (it does not confirm the actual files involved in the copy operation with /QUIT).

Throttling (Copy speed limitation)

[Windows 11 or later] By utilizing the /IoMaxSize and /IoRate options in Robocopy, you can suppress and limit the speed of the copy operation (throttling; this can be used to reduce the load on the system). Generally, copying is performed at the throttling limit specified by /IoMaxSize or /IoRate, but the values may be adjusted by Robocopy depending on the specified values.

Example:

robocopy D:\data\db X:\bk\db *.db /iorate:1M
-- Copy files with the extension *.db, limiting the copy speed to 1M/s

By using the /Threshold option, you can avoid imposing restrictions on files that fall below a certain size.

About job file

A job file is a text file containing the options for Robocopy. Essentially, it is a format that lists the options that can be specified on the command line. (The commands described in the job file are passed directly to the command line.)

Additionally, there are the following advantages compared to the command line.

  • Possible to format using line breaks and spaces : While on the command line, you typically need to specify everything on one line, in a job file, you can split the specification across multiple lines. Additionally, you can freely use space and tab characters, allowing you to describe the content in a more readable format.
  • Possible to include comments in the description : If you write a colon ‘:’ consecutively for two characters, those two characters and the subsequent characters (until a line break) are treated as ‘comments’ and are ignored during command processing. This allows you to make notes about the meaning of options, for example.
  • Possible to specify long command lines : There are character limits when specifying on the command line (In Windows XP or later the limit is set to 8191 characters: Command prompt line string limitation - Windows Client | Microsoft Learn), but there is no such limit when describing in a job file.

As an example, a job file would be described as follows:

:: Comment sample

:: Specifying the source directory for copying
/SD:C:\dbs\r1\         :: Set "C:\dbs\r1" as the source directory for copying
:: Specifying the destination directory for copying
/DD:X:\Backup\dbs\r1\  :: Set "X:\Backup\dbs\r1\" as the destination directory for copying
:: Specifying files to include
/IF *.dat              :: Set "*.dat" as the copy target
    *.db               :: Also set "*.db" as the copy target
:: Copy option
/COPY:DAT              :: Copy data, attributes, and timestamps
:: Other option
/IS                    :: Copy even if same
:: Retry, etc.
/R:5 /W:10             :: Retry up to 5 times with a 10-second wait between retries
:: Log
/TS /BYTES             :: Output sizes in bytes, including timestamps

* Spaces, tab characters, and newline characters can be specified consecutively in multiples.
* ‘/SD:’ and ‘/DD:’ can be omitted only if there is no ‘/IF’ specified before them. In that case, you must always specify <source-path> <dest-path> in that order.

If you save this job file as ‘X:\Backup\MYJOB.RCJ’, you can invoke Robocopy as follows:

set MY_DATE=%DATE:/=_%
robocopy /JOB:X:\Backup\MYJOB /LOG:X:\Backup\Backup_%MY_DATE%.log

In this example, Robocopy will be executed with the options described in MYJOB.RCJ, adding the ‘/LOG’ option. This execution is roughly equivalent to the following command line.

set MY_DATE=%DATE:/=_%
robocopy C:\dbs\r1\ X:\Backup\dbs\r1\ /IF *.dat *.db /COPY:DAT /IS /R:5 /W:10 /TS /BYTES /LOG:X:\Backup\Backup_%MY_DATE%.log

Note that, while job files can be manually written in text format, it's also possible to generate them through Robocopy using the "/SAVE" option. When creating a job file with "/SAVE," descriptions for each option (the explanatory text displayed with ‘robocopy /?’) are saved as comments. Additionally, <source-path>, <dest-path>, and the log file name specified with /LOG are saved as absolute paths (if specified). However, if you specify the /SAVE option in the middle of the command line, options written after it will not be saved, so please be mindful of the order.

If the content specified in the job file overlaps with what is specified on the command line, the content specified on the command line takes precedence if it appears after /JOB. However, if the source and destination directories are specified in the job file, they cannot be overridden by specifying them on the command line.

* If the specification of /JOB on the command line is after <source-path> or <dest-path>, and /SD or /DD is specified in the job file, it will result in an error in the job file.
* It is possible to use /JOB within a job file (similar to an include), but specifying the job file itself will result in a semi-infinite loop. The execution will terminate with an error when it reaches the limit of simultaneously open files.

The character encoding of the job file must match the code page of the environment in which Robocopy is executed (which can be changed with Chcp or Mode).

* If the character encoding of the job file is UTF-8, set the code page with Chcp to ‘65001’. However, when using UTF-8, it seems that non-ASCII character filenames are not handled correctly (as of November 2023, confirmed on Win7/Win10/Win11).

About privileges

Some options require the privilege to execute them. In most cases, if you are an administrator, you have the necessary privileges to run the command without errors. Additionally, options like ‘/B’ can be executed by non-administrator users with backup and restore privileges, not necessarily requiring administrator rights.

[Windows Vista or later] If User Account Control (UAC) is enabled, even if the user has the necessary privileges, the lack of elevation will result in a lack of permissions, causing the command to fail. In this case, you need to elevate using methods such as:

  • Open Command Prompt (or similar) by selecting "Run as administrator" and execute the command within it
  • Enable ‘Run with highest privileges’ when executing as a scheduled task in the Task Scheduler

Robocopy itself does not have the capability to perform elevation, so if you are using options like /B or /COPY:U, please perform privilege elevation. (Even when executed with Runas, it's not sufficient as Runas does not perform UAC privilege elevation. Please refer to the examples of privilege elevation on the Runas page.)

To check whether you have the necessary privileges in the current environment (prompt/batch file), you can use ‘whoami /PRIV’ to display and retrieve a list of privileges, considering UAC elevation.

* If the currently logged-in user has higher privileges than a regular user, you can choose the logged-in user when selecting ‘Run as administrator’. This allows you to open a Command Prompt with the elevated privileges (without explicitly logging in as an administrator).
* If the UAC elevation restrictions are not enabled, you can execute commands without performing these operations (although it is not highly recommended for security reasons).

Exit codes

When Robocopy completes a copy operation, it sets an exit code (error code, return value) based on the operation's outcome. Exit codes are useful when determining conditions using the If Errorlevel statement (and the ERRORLEVEL environment variable).

The exit code of Robocopy is a combination (sum) of the following values:

Value Meaning
0 No action was taken (no files were copied).
1 Files were copied successfully.
2 Files exist in the destination that do not exist in the source.
4 There are files or directories (folders) with the same name but different characteristics.
8 Some files failed to copy.

For example, the exit code ‘3’ means ‘Files were copied, and additional files exist only in the destination’. The exit code ‘6’ means ‘No files were copied, but some files exist only in the destination, and there are mismatched files and directories’. The exit code ‘9’ means ‘Some files were copied, but some files failed to copy’.

※ Generally, an exit code of ‘0’ is considered successful, but in the case of Robocopy, an exit code of ‘less than 8’ (sometimes ‘less than 4’) is considered successful.

This combined exit code can be easily determined in a batch file using the If Errorlevel statement. The If Errorlevel statement checks if the exit code is ‘equal to or greater than’ a specified value, allowing you to write conditions such as ‘greater than or equal to 8’ as follows:

robocopy /JOB:MyJob.rcj
if errorlevel 8 goto OnError
if errorlevel 4 goto OnMismatchedFile

echo The copy operation completed successfully.
goto OnExit

:OnMismatchedFile
echo The copy operation completed, but some files were mismatched.
goto OnExit

:OnError
echo Something went wrong on copying.

:OnExit

Samples

Sample 1

robocopy C:\MyDoc D:\Backup\MyDoc /E

Copies the files and subdirectories contained in C:\MyDoc (included by /E) to D:\Backup\MyDoc. By default, files that already exist in the destination are left as they are, and files that have not changed in data and file timestamp are not copied.

Sample 2

robocopy C:\MyDoc D:\Backup\MyDoc /E /A

Copies only the files and subdirectories contained in C:\MyDoc (included by /E) that have the archive attribute set (/A behavior) to D:\Backup\MyDoc. This behavior is similar to the one in Sample 1 on the Xcopy page.

Sample 3

robocopy H:\Data R:\External\Data /MIR /A+:N

Copies the files contained in H:\Data to R:\External\Data and deletes files that exist only in R:\External\Data (/MIR behavior). Additionally, when new files are copied, it adds the non-index attribute to the destination files (/A+:N behavior).

* This does not change the attributes for files that already exist.

Sample 4

robocopy Z:\Data E:\Current\Data /E /XO

Copies the files and subdirectories contained in Z:\Data (included by /E) to E:\Current\Data. However, if the files on the Z:\Data side are older, it excludes them from the copy (/XO behavior). This behavior is similar to Sample 3 on the Xcopy page.

Sample 5

robocopy D:\Projects\Piyo\Sources X:\Projects\Bar\Sources /E /XA:R

Copies the files and subdirectories contained in D:\Projects\Piyo\Sources (included by /E) to X:\Projects\Bar\Sources. However, if the files on the source or destination side have the read-only attribute, it excludes those files from the copy (/XA:R behavior).

Sample 6

robocopy P:\Logs Q:\Backup\Logs /E /IF access*.* error*.* /XF access_ignore_*.* error_ignore_*.*

copies all the files and subdirectories contained in P:\Logs (included by /E) that match the wildcard specifications ‘access*.*’ or ‘error*.*’ (specified by /IF) to Q:\Backup\Logs. However, files matching ‘access_ignore_*.*’ and ‘error_ignore_*.*’ are excluded (specified by /XF).

Sample 7

robocopy D:\Foo\Bar "F:\Backups\2015 Foo Bar" /JOB:"F:\Backups\Job Files\Op1.rcj" /LOG:"F:\Backups\2015 Foo Bar Log.txt"

Executes the copy operation from ‘D:\Foo\Bar’ to ‘F:\Backups\2015 Foo Bar’ using the job file ‘F:\Backups\Job Files\Op1.rcj’ and records the log in ‘F:\Backups\2015 Foo Bar Log.txt’. The specific details of the copy operation depend on the contents of the job file.

See also