Robocopy Command Builder

Build robocopy copy, mirror and move commands with the right switches.

Advertisement

Robocopy Command Builder

robocopy (Robust File Copy) is the heavy-duty file copier built into Windows. Unlike drag-and-drop or copy, it retries on failure, preserves timestamps and permissions, copies multithreaded, skips files that have not changed, and can mirror an entire folder tree. It is the standard tool for backups, server migrations, and large folder syncs. This builder assembles the command with the right switches and warns you before the destructive ones.

Modes

ModeSwitchWhat it does
Copy/ECopy all subfolders, including empty ones
Mirror/MIRMake destination identical — DELETES extras in the destination
Move/MOVECopy, then delete from the source
Test/LList what would happen — changes nothing

Key switches

  • /COPYALL — copy all file info (data, attributes, timestamps, NTFS permissions, owner, auditing).
  • /Z — restartable mode; resumes a large file after an interruption.
  • /MT:n — multithreaded copy with n threads (default 8) for many small files.
  • /R:n and /W:n — retry count and wait seconds between retries. The default /R:1000000 can hang for days on a locked file, so set something sane like /R:3 /W:5.
  • /XO, /XD, /XF — exclude older files, exclude directories, exclude files.
  • /LOG:file /TEE — write a log and still show output on screen.

Worked examples

robocopy "C:\Source" "D:\Backup" /E /Z /R:3 /W:5 /LOG:robocopy.log /TEE
robocopy "C:\Source" "D:\Backup" /MIR /R:2 /W:5 /XD node_modules .git
robocopy "C:\Source" "D:\Backup" /MIR /L

The first does a resumable recursive copy with a log. The second mirrors a folder while excluding build directories. The third is the safety habit: run /MIR with /L first to preview exactly what would be copied and deleted before doing it for real.

Pitfalls to watch

  • /MIR deletes. Anything in the destination that is not in the source is removed. Point it at the wrong destination and you can wipe data — always test with /L first.
  • /MOVE deletes the source after a successful copy, so verify the destination before relying on it.
  • Robocopy exit codes are bitmapped: 0–7 indicate success (1 = files copied, 3 = copied plus extras), while 8 or higher means a real failure. Do not treat a non-zero exit as an error in scripts.

Frequently Asked Questions

What is the difference between robocopy and xcopy?+

robocopy is the modern, robust replacement for xcopy. It adds multithreaded copying, automatic retries on locked files, mirroring, restartable transfers, detailed logging, and preservation of NTFS permissions. xcopy is older and lacks these features, which is why robocopy is preferred for backups and migrations.

What does robocopy /MIR do?+

The /MIR switch mirrors a directory tree, making the destination an exact copy of the source. It copies new and changed files and, critically, deletes anything in the destination that is not in the source. Always preview it with /L first, because pointing it at the wrong folder can erase data.

Why does robocopy seem to hang on some files?+

By default robocopy retries a failed or locked file one million times, waiting 30 seconds between each attempt, which can stall for days. Add /R:3 /W:5 to retry only three times with a five-second wait so it moves on quickly instead of hanging.

What do robocopy exit codes mean?+

robocopy uses bitmapped exit codes. Values 0 through 7 indicate success: 0 means nothing changed, 1 means files were copied, and higher values in that range mean extras or mismatches were handled. An exit code of 8 or above signals a genuine failure, so scripts should only treat 8+ as an error.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.