Build robocopy copy, mirror and move commands with the right switches.
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.
| Mode | Switch | What it does |
|---|---|---|
| Copy | /E | Copy all subfolders, including empty ones |
| Mirror | /MIR | Make destination identical — DELETES extras in the destination |
| Move | /MOVE | Copy, then delete from the source |
| Test | /L | List what would happen — changes nothing |
/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.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 /LThe 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.
/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 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.
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.
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.
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.