Skip to main content
Home/Blog/Automation/Robocopy Command Guide: Mirror, Copy and Sync (2026)
Automation

Robocopy Command Guide: Mirror, Copy and Sync (2026)

Robocopy examples for every job: mirror a folder with /MIR, copy with /E, resume large transfers with /Z, multithread with /MT, and test safely with /L. Full 2026 switch reference for Windows 10, 11 and Server.

By InventiveHQ Team
Robocopy Command Guide: Mirror, Copy and Sync (2026)

Need to mirror, copy, or sync folders from the command line on Windows? This guide covers every essential robocopy switch — /E, /MIR, /COPYALL, /MT, /Z, /XD and more — with real-world examples and the full exit-code table, for Windows 10, 11 and Server.

Robocopy Command Builder

Build robocopy commands to copy, mirror, or move files with the right switches — multithreading, retries, exclusions, logging, and a safe list-only test mode.

Open the full Robocopy Command Builder
Loading interactive tool...

Verified June 2026 · tested on Windows 11 24H2, Windows 10 22H2 & Server 2022/2025


Quick Reference: Essential Commands

Need to copy or sync a folder right now? Here are the most common commands:

# Copy a folder and all subfolders (additive — never deletes)
robocopy C:\Source D:\Dest /E

# Mirror a folder (exact replica — DELETES extras in the destination)
robocopy C:\Source D:\Dest /MIR

# Robust large copy: resume on failure, retry 3x, multithreaded
robocopy C:\Source D:\Dest /E /Z /R:3 /W:5 /MT:16

# Migrate a share preserving permissions and timestamps
robocopy \\OldServer\Data \\NewServer\Data /COPYALL /DCOPY:T /E /R:1 /W:1

# DRY RUN — list what WOULD happen, change nothing
robocopy C:\Source D:\Dest /MIR /L

# Same job, writing a log file
robocopy C:\Source D:\Dest /E /LOG:C:\Temp\copy.log

Which command do you need?

  • Copy a folder and subfolders (no deletes)/E
  • Make the destination an exact replica/MIR
  • Preserve permissions, owner and timestamps/COPYALL & /COPY:DAT
  • Survive a flaky network / resume a big copy/Z, /R, /W
  • Speed up many-small-file jobs/MT
  • Skip files, folders, or older files/XO, /XD, /XF
  • Test safely before committing/L
  • Keep a record of what happened/LOG

Jump to the section you need below.


Robocopy Syntax Basics

Every Robocopy command follows the same shape:

robocopy <source> <destination> [file(s)] [options]
  • source — the folder to copy from (local path or UNC share).
  • destination — the folder to copy to. Robocopy creates it if it doesn't exist.
  • file(s) — optional filter; defaults to *.* (everything). You can name specific files or wildcards, e.g. *.docx *.xlsx.
  • options — one or more switches that control how the copy runs.

Windows 10Windows 11Server 2016+Built in — no install

Tip: Wrap any path that contains spaces in double quotes — "C:\Program Files\App". A trailing backslash on a quoted path ("C:\My Folder\") can break parsing; use "C:\My Folder" instead, or double the backslash.


/E: Copy Folders and Subfolders

/E copies the source directory and all subdirectories, including empty ones. It is additive: it copies new and changed files but never deletes anything already in the destination. This is the safe, everyday "copy a tree" switch.

Non-destructiveMost common

Directory-Copy Switch Reference

SwitchDescription
/ECopy all subdirectories, including empty ones
/SCopy subdirectories, but skip empty ones
/PURGEDelete destination files/dirs that no longer exist in the source
/MIRMirror — equivalent to /E plus /PURGE (see warning below)
/MOVECopy files and dirs, then delete them from the source
/MOVMove files only (leaves directory structure in the source)
/CREATECreate the directory tree and zero-length files only (no data)

/E Usage Examples

# Copy an entire tree, including empty folders
robocopy C:\Projects D:\Backup\Projects /E

# Copy only non-empty subfolders
robocopy C:\Projects D:\Backup\Projects /S

# Copy only specific file types from the whole tree
robocopy C:\Projects D:\Backup\Projects *.docx *.xlsx /E

# Move a tree to a new disk (source is emptied as it goes)
robocopy C:\OldLocation D:\NewLocation /E /MOVE

Warning: /MOVE and /MOV delete the source once each file is copied. Run the command with /L first to confirm the file list, and verify the destination after the copy completes before relying on the moved data.


/MIR: Mirror a Folder (DESTRUCTIVE)

/MIR (mirror) makes the destination an exact replica of the source. It is /E plus /PURGE, so in addition to copying new and changed files it deletes any file or folder in the destination that no longer exists in the source. This is the right switch for repeatable backups and replication — and the wrong switch if you ever point it at the wrong destination.

Backup & replication⚠ Deletes destination extras

Warning: /MIR permanently deletes files in the destination that are not present in the source — including the destination's own contents if you swap the source and destination paths by mistake. Never run /MIR against a populated folder without first doing a /L dry run. Pointing /MIR at the root of a drive (e.g. D:\) can wipe everything on it.

/MIR Usage Examples

# ALWAYS test first — list what would be copied AND deleted
robocopy C:\Source D:\Mirror /MIR /L

# Looks right? Run it for real
robocopy C:\Source D:\Mirror /MIR

# Robust nightly mirror with retries and a log
robocopy C:\Source D:\Mirror /MIR /R:2 /W:5 /MT:16 /LOG:C:\Temp\mirror.log /NP

# Mirror but DON'T delete the destination's extra files — use /E instead
robocopy C:\Source D:\Backup /E

If you want the additive behaviour of a mirror (copy new and changed files) without the deletions, drop /MIR and use /E. Only /MIR and /PURGE remove files.


/COPYALL, /COPY:DAT and /DCOPY:T: Control What Is Copied

By default Robocopy copies file Data, Attributes and Timestamps (/COPY:DAT). When you need to preserve NTFS permissions, ownership, or folder timestamps — for example migrating a file server — you control exactly what travels with each file.

The /COPY: flags map to letters: D=Data, A=Attributes, T=Timestamps, S=NTFS Security (ACLs), O=Owner info, U=aUditing info.

File-server migration⚠ /COPYALL needs admin rights

Attribute-Copy Switch Reference

SwitchDescription
/COPY:DATDefault. Copy Data, Attributes, Timestamps
/COPYALLCopy everything: /COPY:DATSOU (Data, Attrs, Timestamps, Security, Owner, aUditing)
/COPY:DATSData + Attributes + Timestamps + Security (ACLs)
/SECCopy files with security — shorthand for /COPY:DATS
/DCOPY:TCopy directory timestamps (folders keep their original dates)
/DCOPY:DATCopy directory Data, Attributes and Timestamps
/NOCOPYCopy no file info (used with /PURGE to clean a destination)

Migration Usage Examples

# Full fidelity server migration: data, ACLs, owner, auditing + folder dates
robocopy \\OldSrv\Share \\NewSrv\Share /COPYALL /DCOPY:T /E /R:1 /W:1

# Copy data and NTFS permissions only (no owner/audit)
robocopy C:\Data D:\Data /COPY:DATS /E

# Preserve original folder timestamps on a normal copy
robocopy C:\Source D:\Dest /E /DCOPY:T

Warning: Copying security, owner, and auditing info (/COPYALL, /COPY:...SOU) requires elevated rights. Run the command from an administrator prompt; on a file-server migration you typically need the Back up files and directories and Restore files and directories privileges, or some ACLs will fail to copy.


/Z, /R and /W: Restartable Mode and Retries

Large copies fail. /Z runs in restartable mode so an interrupted file resumes from where it stopped instead of restarting. /R:n and /W:n control how Robocopy handles locked or unavailable files — and their defaults are dangerously high.

Large & network copies⚠ Default /R is 1 million

Reliability Switch Reference

SwitchDescription
/ZRestartable mode — resume a partially copied file after an interruption
/BBackup mode — copy files using the Backup privilege (bypasses ACL read denials)
/ZBUse restartable mode; fall back to backup mode if access is denied
/R:nNumber of retries on a failed copy (default: 1,000,000)
/W:nWait seconds between retries (default: 30)
/TBDWait for share names to be defined (retry on "ERROR 67")

Reliability Usage Examples

# Robust large copy: resume support, 3 retries, 5-second waits
robocopy C:\Source D:\Dest /E /Z /R:3 /W:5

# Network copy over an unreliable link
robocopy \\Server\Share D:\Local /E /Z /R:5 /W:10

# Copy locked/in-use files using backup mode (run as admin)
robocopy C:\Source D:\Dest /E /ZB /R:2 /W:5

Tip: Always set /R and /W explicitly. The factory defaults — 1,000,000 retries with a 30-second wait — mean a single locked file can stall a job for weeks. /R:3 /W:5 is a sane starting point for almost every scenario.


/MT: Multithreaded Copying

/MT:n copies files using n parallel threads (1–128, default 8). For folders full of many small files this can cut copy time dramatically. It has little effect on a handful of very large files or a slow single disk.

Many small files⚠ Incompatible with /Z and /IPG

Performance Switch Reference

SwitchDescription
/MT:nCopy with n threads (1–128, default 8)
/NPNo progress percentage (cleaner logs; recommended with /MT)
/NFL / /NDLNo file list / no directory list in output
/JCopy using unbuffered I/O — best for very large files
/IPG:nInter-packet gap (ms) to throttle bandwidth on slow links
/COMPRESSRequest SMB compression (Windows 11 / Server 2022+)

/MT Usage Examples

# 16 threads for a large set of small files, quiet output
robocopy C:\Source D:\Dest /E /MT:16 /NP /NFL /NDL

# 32 threads with a clean log file
robocopy C:\Source D:\Dest /E /MT:32 /LOG:C:\Temp\copy.log /NP

# Very large single files: unbuffered I/O instead of many threads
robocopy C:\VMs D:\VMs /E /J

Note: /MT cannot be combined with /Z (restartable) or /IPG (throttling). If you need both speed and resume support on a flaky link, run separate passes — multithreaded first, then a /Z cleanup pass for any files that failed.


/XO, /XD and /XF: Excluding Files and Folders

Robocopy's exclusion switches keep junk out of your copy and skip files you don't want to overwrite. /XO excludes older files (so you never overwrite a newer destination copy with an older source).

FilteringSelective sync

Exclusion Switch Reference

SwitchDescription
/XF {files}Exclude files matching these names/wildcards
/XD {dirs}Exclude directories matching these names/paths
/XOExclude older files (skip source files older than the destination)
/XNExclude newer files
/XCExclude changed files
/XXExclude extra files/dirs (present only in the destination) — opposite of purge
/XLExclude lonely files/dirs (present only in the source)
/MAXAGE:n / /MINAGE:nExclude files older / newer than n days (or a date YYYYMMDD)

Exclusion Usage Examples

# Exclude temp folders and log/temp files from a tree copy
robocopy C:\Source D:\Dest /E /XD "C:\Source\temp" node_modules .git /XF *.tmp *.log

# Never overwrite a newer file in the destination
robocopy C:\Source D:\Dest /E /XO

# Copy only files changed in the last 7 days
robocopy C:\Source D:\Dest /E /MAXAGE:7

# Mirror, but keep destination-only files (no deletions of extras)
robocopy C:\Source D:\Dest /MIR /XX

Tip: /XD matches against the directory name and full path. To exclude a folder anywhere in the tree, give just its name (node_modules); to exclude one specific folder, give its full path in quotes.


/L: List-Only Dry Run

/L is the most important safety switch in Robocopy. With /L, Robocopy logs every file it would copy or delete but makes no changes whatsoever. Treat it as mandatory before any /MIR, /PURGE, /MOVE, or first-time job.

Safety firstNo changes made

/L Usage Examples

# Preview exactly what a mirror would copy AND delete
robocopy C:\Source D:\Dest /MIR /L

# Combine with logging to capture the preview for review
robocopy C:\Source D:\Dest /MIR /L /LOG:C:\Temp\preview.log

# Count how many files/bytes a job would move (read the summary footer)
robocopy C:\Source D:\Dest /E /L /NFL /NDL

The output marks each file with what would happen — New File, Newer, *EXTRA File (would be deleted by /MIR or /PURGE), and so on. Read the summary footer for total counts, confirm it matches your intent, then re-run the identical command with /L removed.


/LOG: Writing to a Log File

For scheduled jobs and migrations you want a record. /LOG writes Robocopy's output to a file so you can review results, troubleshoot failures, and audit what moved.

Logging Switch Reference

SwitchDescription
/LOG:{file}Write output to a log file (overwrites each run)
/LOG+:{file}Append output to an existing log file
/TEEShow output in the console and write to the log
/NPNo per-file progress percentage (avoids huge logs)
/VVerbose — also log skipped files
/TS / /FPInclude file timestamps / full pathnames in the log

/LOG Usage Examples

# Overwrite a fresh log each run, no noisy progress lines
robocopy C:\Source D:\Dest /E /LOG:C:\Temp\copy.log /NP

# Append to a running history and still watch the console
robocopy C:\Source D:\Dest /MIR /LOG+:C:\Temp\nightly.log /TEE /NP

# Verbose log with full paths and timestamps for an audit
robocopy C:\Source D:\Dest /E /V /TS /FP /LOG:C:\Temp\audit.log

Robocopy Exit Codes (Bitmask) Reference

Robocopy does not return a simple 0/1 result — it returns a bitmask, so multiple conditions can combine (e.g. 3 = files copied and extras detected = 1 + 2). In scripts, treat any value below 8 as success and 8 or higher as failure. Check it immediately with echo %ERRORLEVEL% (cmd) or $LASTEXITCODE (PowerShell). Each row is deep-linkable — share a specific code with …#rc-8, and the row highlights on arrival.

Exit code (bit)MeaningAction
0No files copied — source and destination already in syncNothing to do; this is a clean success
1 (bit 0)One or more files were copied successfullyNormal success
2 (bit 1)Extra files or directories exist in the destination (not in source)Expected unless you mirror; add /PURGE or /MIR to remove them
3Files copied and extras detected (1 + 2)Success — both conditions are informational
4 (bit 2)Mismatched files or directories (e.g. a file in the source matches a folder name in the destination)Investigate; housekeeping needed
5Files copied + mismatches (1 + 4)Copy succeeded but resolve the mismatches
7Files copied + extras + mismatches (1 + 2 + 4)Copy succeeded; review extras and mismatches
8 (bit 3)Some files or directories could not be copied (retry limit exceeded)Failure — check the log, raise /R//W or fix locked files/permissions
16 (bit 4)Fatal error — Robocopy did not copy any files (bad path, out of memory, invalid switch)Failure — verify the command line, paths, and access rights

A robust scheduled-task check in cmd:

robocopy C:\Source D:\Dest /MIR /R:2 /W:5 /LOG:C:\Temp\job.log
if %ERRORLEVEL% GEQ 8 (echo ROBOCOPY FAILED & exit /b 1) else (echo OK & exit /b 0)

Version and Compatibility Notes

  • Windows 10 / 11: Robocopy ships built into every edition (including Home) — no install or feature needed. /MT, /Z, /MIR and the exclusion switches behave identically across modern versions.
  • Windows Server: Identical behaviour; /COPYALL and /B//ZB backup modes are the standard tools for file-server migrations. Run elevated to copy ACLs, owner and auditing data.
  • SMB compression (/COMPRESS): Requires Windows 11 / Windows Server 2022 or later on both ends; it negotiates SMB-level compression to speed transfers over slow links.
  • /MT exclusions: /MT cannot be combined with /Z (restartable) or /IPG (throttling). Choose speed or resume-on-failure per pass.
  • Long paths: Robocopy natively supports paths longer than 260 characters, which is why it succeeds on deep folder trees where Explorer drag-and-drop fails.
  • Permissions: Copying data needs read on the source and write on the destination; copying security/owner/audit info (/COPYALL) needs administrator rights and, ideally, the Back up and Restore privileges.

Robocopy ("Robust File Copy") has been part of Windows since Vista and is the most reliable built-in tool for copying, mirroring and migrating folders. When in doubt, reach for /L first — a dry run costs seconds and prevents the one mistake (/MIR against the wrong destination) that Robocopy can't undo.

Frequently Asked Questions

Find answers to common questions

Run 'robocopy C:\Source D:\Destination /MIR'. The /MIR switch makes the destination an exact copy of the source — it copies new and changed files AND deletes anything in the destination that no longer exists in the source. Always run it first with /L added (a list-only dry run) so you can see exactly what would be copied and deleted before committing.

'/E' copies all subdirectories including empty ones but never deletes anything in the destination — it only adds and updates. '/MIR' (mirror) is /E plus /PURGE, so it also DELETES files and folders in the destination that are not in the source. Use /E for an additive copy or backup; use /MIR only when you want the destination to be an identical replica.

Add the '/Z' switch (restartable mode), which lets Robocopy resume a partially copied file from where it stopped instead of starting over. A typical large-file copy is 'robocopy C:\Source D:\Dest /E /Z /R:3 /W:5'. For network copies over unreliable links, /Z is essential, though it is slightly slower than normal mode.

'/COPYALL' copies every file attribute: Data, Attributes, Timestamps, NTFS Security (ACLs), Owner info, and Auditing info — it is the equivalent of '/COPY:DATSOU'. Use it when you need to preserve permissions and ownership, for example when migrating a file server. Copying security info usually requires running the command as an administrator with the 'Back up files and directories' privilege.

Use '/XD' to exclude directories and '/XF' to exclude files. For example, 'robocopy C:\Source D:\Dest /E /XD "C:\Source\temp" node_modules /XF *.tmp *.log' copies everything except the temp and node_modules folders and any .tmp or .log files. You can list multiple names after each switch, and wildcards are supported.

Add the '/L' switch. It performs a list-only dry run: Robocopy logs every file it WOULD copy or delete but makes no changes. This is the single most important safety step before running /MIR or /PURGE — confirm the list looks right, then re-run the same command with /L removed.

Robocopy returns a bitmask, not a simple success/failure code. 0 means no files were copied (nothing to do), 1 means files were copied successfully, 2 means extra files/dirs exist in the destination, and higher bits indicate mismatches (4), copy failures (8), and fatal errors (16). Any exit code below 8 is considered success in scripts; 8 or higher signals at least one failure. Check 'echo %ERRORLEVEL%' right after the command.

'/MT:n' sets the number of copy threads (1 to 128, default 8). For many small files, increasing to /MT:16 or /MT:32 can dramatically speed up the job. For a few very large files or a slow single-spindle disk, more threads offer little benefit and can cause contention. Start with /MT:16 and test — /MT is incompatible with /Z and /IPG.

Transform Your IT with Automation

Streamline operations, reduce manual tasks, and improve security with intelligent automation.