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
| Switch | Description |
|---|---|
/E | Copy all subdirectories, including empty ones |
/S | Copy subdirectories, but skip empty ones |
/PURGE | Delete destination files/dirs that no longer exist in the source |
/MIR | Mirror — equivalent to /E plus /PURGE (see warning below) |
/MOVE | Copy files and dirs, then delete them from the source |
/MOV | Move files only (leaves directory structure in the source) |
/CREATE | Create 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:
/MOVEand/MOVdelete the source once each file is copied. Run the command with/Lfirst 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:
/MIRpermanently 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/MIRagainst a populated folder without first doing a/Ldry run. Pointing/MIRat 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
| Switch | Description |
|---|---|
/COPY:DAT | Default. Copy Data, Attributes, Timestamps |
/COPYALL | Copy everything: /COPY:DATSOU (Data, Attrs, Timestamps, Security, Owner, aUditing) |
/COPY:DATS | Data + Attributes + Timestamps + Security (ACLs) |
/SEC | Copy files with security — shorthand for /COPY:DATS |
/DCOPY:T | Copy directory timestamps (folders keep their original dates) |
/DCOPY:DAT | Copy directory Data, Attributes and Timestamps |
/NOCOPY | Copy 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
| Switch | Description |
|---|---|
/Z | Restartable mode — resume a partially copied file after an interruption |
/B | Backup mode — copy files using the Backup privilege (bypasses ACL read denials) |
/ZB | Use restartable mode; fall back to backup mode if access is denied |
/R:n | Number of retries on a failed copy (default: 1,000,000) |
/W:n | Wait seconds between retries (default: 30) |
/TBD | Wait 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
/Rand/Wexplicitly. 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:5is 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
| Switch | Description |
|---|---|
/MT:n | Copy with n threads (1–128, default 8) |
/NP | No progress percentage (cleaner logs; recommended with /MT) |
/NFL / /NDL | No file list / no directory list in output |
/J | Copy using unbuffered I/O — best for very large files |
/IPG:n | Inter-packet gap (ms) to throttle bandwidth on slow links |
/COMPRESS | Request 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:
/MTcannot 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/Zcleanup 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
| Switch | Description |
|---|---|
/XF {files} | Exclude files matching these names/wildcards |
/XD {dirs} | Exclude directories matching these names/paths |
/XO | Exclude older files (skip source files older than the destination) |
/XN | Exclude newer files |
/XC | Exclude changed files |
/XX | Exclude extra files/dirs (present only in the destination) — opposite of purge |
/XL | Exclude lonely files/dirs (present only in the source) |
/MAXAGE:n / /MINAGE:n | Exclude 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:
/XDmatches 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
| Switch | Description |
|---|---|
/LOG:{file} | Write output to a log file (overwrites each run) |
/LOG+:{file} | Append output to an existing log file |
/TEE | Show output in the console and write to the log |
/NP | No per-file progress percentage (avoids huge logs) |
/V | Verbose — also log skipped files |
/TS / /FP | Include 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) | Meaning | Action |
|---|---|---|
0 | No files copied — source and destination already in sync | Nothing to do; this is a clean success |
1 (bit 0) | One or more files were copied successfully | Normal 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 |
3 | Files 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 |
5 | Files copied + mismatches (1 + 4) | Copy succeeded but resolve the mismatches |
7 | Files 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,/MIRand the exclusion switches behave identically across modern versions. - Windows Server: Identical behaviour;
/COPYALLand/B//ZBbackup 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. /MTexclusions:/MTcannot 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.






