How to use it

  1. Type the source folder and the destination folder. Do not add quotes. The tool adds them when a path needs them.
  2. To copy only some files, type patterns such as *.docx *.xlsx.
  3. Tick the switches you need. Each one has a short explanation.
  4. Read any red warning under the command.
  5. Tick /L for a test run first. It lists what would happen and changes nothing.
  6. Press Copy command and paste it into a command prompt.

The trailing backslash problem

A path such as "C:\My Folder\" breaks robocopy. Windows reads the backslash before the closing quote as an escape, so the quote becomes part of the path. Robocopy then fails with an odd error about the path. This tool removes the last backslash from a quoted path, which fixes it.

/MIR, /MOV and /MOVE delete things

/MIR makes the destination an exact copy of the source. It deletes every file in the destination that is not in the source. If you swap the two paths by mistake, you lose data. /MOV and /MOVE delete from the source after the copy. Always run these with /L first and read the list.

Set /R and /W

By default robocopy retries a failed file 1 million times and waits 30 seconds each time. One locked file can hold up a job for a very long time. /R:3 /W:5 is a common choice.

Robocopy exit codes

Robocopy does not return 0 for every success. The exit code is a sum of flags.

CodeMeaning
0Nothing to copy. Source and destination already match.
1Files were copied.
2Extra files or folders are in the destination.
4Mismatched files or folders were found.
8Some files or folders could not be copied.
16Serious error. Robocopy copied nothing.

Codes add up, so 3 means files were copied and extra files exist. Codes 0 to 7 mean the run worked. Codes 8 and above mean something failed.

Robocopy in an SCCM program or task sequence

Configuration Manager treats any exit code other than 0 as a failure, unless you tell it otherwise. A good copy that returns 1 then shows as a failed deployment. Wrap the command in a batch file and turn the code into 0 when it is below 8:

robocopy C:\Src D:\Dst /E /R:3 /W:5
if %ERRORLEVEL% LSS 8 exit /b 0
exit /b %ERRORLEVEL%

For an application deployment type, you can also add 1, 2 and 3 as success codes on the Return Codes tab.

Questions

What is the difference between /E and /MIR?

Both copy all subfolders. /MIR also deletes files and folders in the destination that are not in the source. /E never deletes anything.

Why does robocopy return exit code 1 when nothing went wrong?

Exit code 1 means files were copied. It is a success code. Only codes of 8 and above mean a failure.

How many threads should I use with /MT?

The default is 8. Try 16 or 32 for many small files on a fast network. More threads do not help much with a few large files.

Does /COPYALL need administrator rights?

Yes. It copies the owner and the auditing settings, and those need an elevated prompt. Without the rights, robocopy reports an error for each file.