Skip to content
GEEKnodes

Windows

Robocopy: Copy and Sync Large Folders in Windows Reliably

Robocopy guide for Windows: /E, /MIR and its danger, /Z, /R and /W, /MT, exclusions, logs and exit codes to copy large folders without failures.

Copying 200 GB with File Explorer usually ends the same way: a file with a path too long, an error halfway and doubt about what was copied. Robocopy comes with Windows, retries on its own, logs everything and can resume where it stopped. This guide shows the options that really matter and the one that can delete data if misused.

In short

  • robocopy source destination /E copies everything, empty subfolders included, and on a second pass copies only what changed.
  • /MIR makes the destination identical to the source, which includes deleting whatever does not exist in the source.
  • An exit code of 1 is not an error: only 8 and above means failures.

Why Robocopy instead of Explorer

File ExplorerRobocopy
If a file failsStops and asksRetries and continues
Second copy of the same folderAsks to replaceSkips what is already the same
Very long pathsMay failSupported
Record of copiesNoYes, with /LOG
Parallel copyNoYes, with /MT
Resume after network dropNoYes, with /Z
AutomatableNoYes, in scripts and scheduled tasks

Explorer is fine for a few files. For large copies, external drives, NAS or periodic backups, Robocopy is more reliable and tells you exactly what happened.

Basic syntax

Open Terminal, PowerShell or Command Prompt. The structure is:

robocopy "C:\Origen" "D:\Destino" [archivos] [opciones]
Comparison: without options only the root is copied, with /S subfolders without empty ones and with /E the whole tree.
Without /E, Robocopy copies only the root folder’s files.

Without options, Robocopy copies only the files in the root folder, no subfolders. It is the first scare for many: run it, it finishes instantly and almost all data is missing.

To copy the full tree:

robocopy "C:\Usuarios\Ana\Fotos" "E:\Copia\Fotos" /E
  • /S copies subfolders, but not empty ones.
  • /E copies subfolders including empty ones. Usually what you want.

If you repeat the command, Robocopy compares size and date and copies only new or changed files. A second pass on a huge folder takes seconds.

/MIR: sync, carefully

Source with A, B and C; destination with A, B and D. After /MIR the destination has A, B and C and D is deleted.
/MIR copies what is new and deletes from the destination what is not in the source.
robocopy "C:\Proyectos" "E:\Copia\Proyectos" /MIR

/MIR equals /E plus /PURGE: it copies everything and deletes from the destination any file or folder not in the source. Perfect for an exact replica, and dangerous for three reasons:

  1. Source and destination swapped. Robocopy “syncs” your good folder with the old copy and deletes what is newer.
  2. Empty or wrong source. If the source is an unmounted drive or a mistyped empty folder, the destination ends up empty too.
  3. Destination with other data. Pointing /MIR at the root of a drive holding other things removes everything not in the source.

What Robocopy deletes does not go to the Recycle Bin.

Protection is simple: run with /L first. It lists what it would do without copying or deleting.

robocopy "C:\Proyectos" "E:\Copia\Proyectos" /MIR /L

In the output, lines marked *EXTRA File or *EXTRA Dir are what would be deleted. If you see one you did not expect, stop.

Options for large copies and unstable networks

/Z: restartable mode

With /Z, if a large file copy is interrupted, Robocopy continues where it left off. Useful over networks or with multi-gigabyte files. In exchange it is a bit slower on fast local drives, so do not add it by habit.

/R and /W: retries

By default Robocopy retries each failing file a million times, waiting 30 seconds between attempts. With a locked file the copy hangs practically forever. Set sensible values:

robocopy "C:\Datos" "\\NAS\Copias\Datos" /E /R:3 /W:5

Three retries with five seconds cover short network drops. What still fails is logged.

/MT: multithreaded copy

/MT copies several files at once. Without a number it uses 8 threads; 1 to 128 allowed.

robocopy "C:\Datos" "E:\Datos" /E /MT:16

It shows most with many small files, especially to a NAS. With a few huge files on a mechanical drive it barely helps and may be worse as the disk jumps between files. Try 8 or 16 before going higher.

Exclude folders and files

/XD excludes folders and /XF files. They accept several values and wildcards:

robocopy "C:\Proyectos" "E:\Copia" /E /XD node_modules .git "Temp" /XF *.tmp *.log Thumbs.db

Name exclusions apply at any level. /XD node_modules excludes all folders with that name, not just the root one. To exclude a specific one, give its full path.

Important with /MIR: excluded items are not deleted from the destination for being excluded, because Robocopy ignores them both ways.

Logging: know what happened

robocopy "C:\Datos" "E:\Datos" /E /R:3 /W:5 /LOG:"C:\Logs\copia.txt" /NP /TEE
  • /LOG:file saves output to a file, overwriting each time. /LOG+:file appends.
  • /NP removes the progress percentage. Without it the log fills with unreadable percent lines.
  • /TEE also shows output on screen.

At the end of the log there is a summary table with Copied, Skipped, FAILED and Extras for folders, files and bytes. Look at the failures column first; if not zero, search for ERROR in the file to see which failed and why.

Exit codes

Robocopy returns a number that is a sum of flags. It confuses script users, because almost all programs return 0 when fine and Robocopy does not.

Flags 1, 2, 4, 8 and 16 added together; 0 to 7 means the copy is fine and 8 or more means failures.
Codes add up: 0 to 7 fine, 8 or more something failed.
CodeMeaning
0Nothing to copy: source and destination already match
1Files copied successfully
2Extra files or folders in the destination
4Mismatched files; check the log
8Some files or folders could not be copied
16Serious error: nothing copied (missing path, no permission…)

Values combine: 3 is 1 + 2 (copied files and extras in destination). Rule of thumb: 0 to 7 fine; 8 or more something failed.

In a .bat file:

robocopy "C:\Datos" "E:\Datos" /E /R:3 /W:5 /LOG:"C:\Logs\copia.txt" /NP
if %ERRORLEVEL% GEQ 8 (
    echo Copy failed. Check the log.
    exit /b 1
)
exit /b 0

In PowerShell the code is in $LASTEXITCODE:

robocopy "C:\Datos" "E:\Datos" /E /R:3 /W:5 /NP
if ($LASTEXITCODE -ge 8) { Write-Error "Robocopy failed ($LASTEXITCODE)" }

Backup template

For a replica of a folder on an external drive or NAS, this combination covers most cases:

robocopy "C:\Usuarios\Ana\Documentos" "E:\Copia\Documentos" /MIR /Z /R:3 /W:5 /MT:8 /XF *.tmp /LOG:"C:\Logs\copia-documentos.txt" /NP

Run it first with /L added and check the list. Once it works, schedule it with Task Scheduler to run nightly.

Common mistakes

  • Trailing slash inside quotes. "D:\Destination\" makes \" an escaped quote and Robocopy gets a broken path. Write "D:\Destination" without trailing slash, or D:\ without quotes.
  • Forgetting /E and copying only the root folder.
  • Leaving /R and /W default and watching the copy “hang” for hours on a locked file.
  • Using /MIR without testing with /L, or with source and destination swapped.
  • Treating code 1 as an error in a script or Task Scheduler, which flags it as failure though all is fine.
  • Files copied again and again on FAT32 or exFAT or some NAS. Those store time less precisely and Robocopy thinks files changed. Add /FFT to accept a 2-second difference.
  • Files in use like an open Outlook .pst or active databases. Robocopy cannot copy them while locked; close them first.

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor