Robocopy command builder
Choose what the copy should do and get a robocopy command with quoting, retries and logging filled in. Further down: paste a command to have it explained, an exit code decoder for scripts and RMM jobs, and every switch.
Command
robocopy <source> <destination>
Explain a robocopy command
Paste a robocopy command to see what each part does and what to check before it runs.
| Part | What it does |
|---|
Robocopy exit codes
Robocopy does not use 0 for success and everything else for failure. Its exit code is a sum of flags, and any value below 8 means no file failed to copy. A scheduler or RMM tool that treats every non-zero code as an error reports a normal copy, exit code 1, as failed.
| Flag | Meaning when set |
|---|---|
| 1 | One or more files were copied. |
| 2 | Extra files or folders were found in the destination that are not in the source. /MIR and /PURGE delete them; otherwise they are left alone. |
| 4 | Mismatched files or folders were found, such as a file in the source where the destination has a folder of the same name. These need a manual look. |
| 8 | Some files or folders could not be copied. Copy errors occurred or the retry limit was reached. |
| 16 | Serious error. Robocopy copied nothing: the command line was wrong, or it had no access to the source or destination. |
An exit code of 0 means nothing was copied and nothing failed: source and destination already match. Add the flags for other values, so 3 is "files copied, extra files present" and 9 is "some files copied, some failed".
Use the exit code in a script
Batch file or RMM command step:
robocopy "C:\Data" "\\server\share\Data" /E /R:2 /W:5 /NP /LOG:"C:\Logs\copy.log"
if %ERRORLEVEL% GEQ 8 exit /b %ERRORLEVEL%
exit /b 0
PowerShell:
robocopy 'C:\Data' '\\server\share\Data' /E /R:2 /W:5 /NP /LOG:'C:\Logs\copy.log'
if ($LASTEXITCODE -ge 8) { exit $LASTEXITCODE }
exit 0
Robocopy switches
Every switch of robocopy, in the groups its own help uses. The explainer above reads this table.
| Switch | What it does |
|---|---|
| Copying | |
/S | Copy subfolders, skipping empty ones. |
/E | Copy subfolders, including empty ones. |
/LEV:n | Copy only the top n levels of the source tree. |
/Z | Restartable mode: an interrupted file resumes where it stopped. Slower than a normal copy. |
/B | Backup mode: read and write files regardless of their permissions, using the backup and restore privileges. |
/ZB | Restartable mode that switches to backup mode when access is denied. |
/J | Unbuffered I/O. Suits very large files. |
/EFSRAW | Copy EFS-encrypted files in raw mode: the encrypted data is copied as it is. |
/COPY:flags | Which file properties to copy: D data, A attributes, T timestamps, X skip alternate data streams, S NTFS permissions, O owner, U auditing. The default is DAT. |
/DCOPY:flags | Which folder properties to copy: D data, A attributes, T timestamps, E extended attributes, X skip alternate data streams. The default is DA. |
/SEC | Same as /COPY:DATS: also copy NTFS permissions. |
/COPYALL | Same as /COPY:DATSOU: copy every file property. |
/NOCOPY | Copy no file properties. Useful together with /PURGE. |
/SECFIX | Fix the permissions on all files, the skipped ones too. |
/TIMFIX | Fix the timestamps on all files, the skipped ones too. |
/PURGE | Delete files and folders in the destination that are no longer in the source. |
/MIR | Mirror the tree: /E plus /PURGE. Deletes anything in the destination that is not in the source. |
/MOV | Move files: delete each file from the source after it is copied. |
/MOVE | Move files and folders: delete both from the source after copying. |
/A+:attributes | Add the named attributes to the copied files: R read only, A archive, S system, H hidden, C compressed, N not content indexed, E encrypted, T temporary. |
/A-:attributes | Remove the named attributes from the copied files. The same letters, and O for offline. |
/CREATE | Create the folder tree and zero-length files only. |
/FAT | Create the destination files with 8.3 FAT names only. |
/256 | Turn off support for paths longer than 256 characters. |
/MON:n | Watch the source and run again when more than n changes are seen. |
/MOT:m | Watch the source and run again in m minutes if something changed. |
/RH:hhmm-hhmm | The hours of the day during which new copies may start. |
/PF | Check those hours for each file, not once per pass. |
/IPG:n | Wait n milliseconds between packets, to leave bandwidth free on slow lines. |
/SJ | Copy junctions as junctions, not what they point to. |
/SL | Copy symbolic links as links, not what they point to. |
/MT:n | Copy n files at a time, 1 to 128, default 8. Cannot be combined with /IPG or /EFSRAW. |
/NODCOPY | Copy no folder properties. Without it, /DCOPY:DA applies. |
/NOOFFLOAD | Copy without the Windows copy offload mechanism. |
/COMPRESS | Ask for network compression during the transfer, where it is available. |
/SPARSE:y|n | Keep (y) or drop (n) the sparse state of files. Keeps it when no value is given. |
/NOCLONE | Do not try block cloning to speed up the copy. |
| Throttling | |
/IOMAXSIZE:n[kmg] | The largest I/O size for one read or write cycle, in kilobytes, megabytes or gigabytes. |
/IORATE:n[kmg] | The I/O rate to hold to, per second. |
/THRESHOLD:n[kmg] | The file size from which throttling applies. Smaller files are not throttled. |
| Choosing files | |
/A | Copy only files that have the Archive attribute set. |
/M | Copy only files that have the Archive attribute set, and clear it. |
/IA:attributes | Include only files that have any of the named attributes: R read only, A archive, S system, H hidden, C compressed, N not content indexed, E encrypted, T temporary, O offline. |
/XA:attributes | Exclude files that have any of the named attributes. The same letters. |
/XF name ... | Exclude files by name, path or wildcard. |
/XD name ... | Exclude folders by name or path. |
/XC | Exclude changed files: the same timestamp, a different size. |
/XN | Exclude source files that are newer than the copy in the destination. |
/XO | Skip source files that are older than the copy already in the destination. |
/XX | Exclude extra files and folders: in the destination, not in the source. Nothing is deleted from the destination. |
/XL | Exclude lonely files and folders: in the source, not in the destination. No new file reaches the destination. |
/IM | Include modified files: the same but for their change time. |
/IS | Include same files: identical in name, size, times and attributes. They are copied again. |
/IT | Include tweaked files: the same name, size and times, different attributes. |
/MAX:n | Exclude files larger than n bytes. |
/MIN:n | Exclude files smaller than n bytes. |
/MAXAGE:n | Exclude files last modified more than n days ago, or before a date. An n below 1900 counts days; a larger one is a date, YYYYMMDD. |
/MINAGE:n | Exclude files last modified less than n days ago, or after a date. Days or a date, as for /MAXAGE. |
/MAXLAD:n | Exclude files not used since n. Days or a date, as for /MAXAGE. |
/MINLAD:n | Exclude files used since n. Days or a date, as for /MAXAGE. |
/XJ | Skip junction points. Without it, a junction that points back into the tree, as in user profiles, can make the copy loop. |
/XJD | Skip junction points to folders. |
/XJF | Skip junction points to files. |
/FFT | Compare file times with 2-second precision, for targets that round timestamps. |
/DST | Allow for one-hour daylight saving time differences. |
/IF name ... | Include only the files named after it. |
| Retries | |
/R:n | Retries for each failed file. The default is 1,000,000. |
/W:n | Seconds to wait between retries. The default is 30. |
/REG | Save /R and /W as the defaults in the registry. |
/TBD | Wait for share names to be defined (retry on error 67). |
/LFSM:n[kmg] | Low free space mode: pause when a copy would take the destination below a floor of free space. The floor is 10% of the volume when no size is given. Cannot be combined with /MT or /EFSRAW. |
| Logging and output | |
/L | List only. Shows what would be copied or deleted without doing it. |
/X | Report all extra files, not only the selected ones. |
/V | Verbose output that also lists skipped files. |
/TS | Show source file timestamps in the output. |
/FP | Show the full path of each file in the output. |
/BYTES | Show sizes in bytes. |
/NS | Leave file sizes out of the output. |
/NC | Leave file classes out of the output. |
/NFL | Leave file names out of the output. |
/NDL | Leave folder names out of the output. |
/NP | Leave out the percentage progress. |
/ETA | Show the estimated time of arrival of the files being copied. |
/LOG:file | Write the output to a log file, replacing the file. |
/LOG+:file | Append the output to a log file. |
/UNILOG:file | Write the output to a log file as Unicode text, replacing the file. |
/UNILOG+:file | Append the output to a log file as Unicode text. |
/TEE | Write to the console as well as the log file. |
/NJH | Leave out the job header. |
/NJS | Leave out the job summary. |
/UNICODE | Show the output as Unicode text. |
| Job files | |
/JOB:name | Take the parameters from the named job file. |
/SAVE:name | Save the parameters to the named job file. |
/QUIT | Stop after reading the command line, to show the parameters. |
/NOSD | No source folder is given. |
/NODD | No destination folder is given. |
More Windows tools
-
Windows error code lookup
Look up 0x80070005, 0xC000006D, 1603 or any other system error, HRESULT, NTSTATUS or bug check code.
-
Msiexec silent install builder
Build install, uninstall and repair commands and look up MSI exit codes.
-
PowerShell EncodedCommand decoder
Read the script inside an encoded PowerShell command, layer by layer, or encode one.
-
.reg file value decoder
hex(2), hex(7), hex(b) and dword values of a .reg file as text and numbers, and a value written as .reg lines.
-
Certificate decoder
Read a certificate, a chain or a request: names, dates, thumbprint, template and account SID.
-
Access mask decoder
Read an access mask such as 0x1200A9 or -1610612736 as file, registry or Active Directory rights.
-
icacls explainer and command builder
Read icacls output such as (OI)(CI)(RX) in plain words, or build commands to grant, deny and remove rights.
-
KMS client keys and slmgr commands
Get the KMS client setup key (GVLK) of a Windows or Windows Server edition and the slmgr commands to activate it.
-
File hash checker
Work out the SHA-256, SHA-1, SHA-512 or MD5 hash of a file in your browser and compare it with the publisher's.
-
File type from its first bytes
What a file is by its first bytes, not its name: PDF, ZIP, Office, EXE or DLL with its CPU and bitness.
-
Zone.Identifier reader
The Mark of the Web on a downloaded file: its zone and address, and the commands that show and remove it.
-
Windows and IANA time zone names
Eastern Standard Time to America/New_York or America/Toronto and back, with tzutil, PowerShell and timedatectl.