|

How To Use The Robocopy Command In Windows (2026)

Robocopy copies files and folders from one location to another and can resume, retry and log the job for you.

The basic form is robocopy <source> <destination> [options], typed in Command Prompt.

This guide uses Microsoft’s robocopy reference, so every option and exit code below is documented.

Table of Contents

Robocopy quick answers

I want toType this
Copy a folder with all subfoldersrobocopy C:\Source D:\Backup /E
Mirror a folder exactlyrobocopy C:\Source D:\Backup /MIR
Copy faster with several threadsrobocopy C:\Source D:\Backup /E /MT:16
Preview without copyingrobocopy C:\Source D:\Backup /E /L
Save a log filerobocopy C:\Source D:\Backup /E /LOG:C:\Logs\copy.log

The robocopy syntax

The syntax is robocopy <source> <destination> [<file>[ ...]] [<options>].

The source and destination are directories, not single files.

The optional file part names the files to copy, accepts the wildcards * and ?, and defaults to all files.

Microsoft’s own example copies one file: robocopy c:\reports "\\marketing\videos" yearly-report.mov /mt /z.

Microsoft warns that data copied from the root of a device makes the destination directory adopt the hidden and system attributes.

Run robocopy

  1. Press the Windows key and type cmd.
  2. Select Command Prompt.
  3. Type your robocopy command and press Enter.

Add quotation marks around any path that contains spaces.

To copy files you do not have rights to, first open Terminal as administrator.

Copy a folder and its subfolders

To bring subfolders along, add one of the switches Microsoft lists below.

OptionWhat it does
/sCopies subdirectories but excludes empty directories.
/eCopies subdirectories and includes empty directories.
/lev:<n>Copies only the top n levels of the source tree.

Microsoft’s first example is robocopy C:\Users\Admin\Records D:\Backup /E /ZB /LOG:C:\Logs\Backup.log.

What gets copied by default

The /copy:<flags> option picks which file properties to copy.

FlagMeaning
DData
AAttributes
TTimestamps
SNTFS ACLs (security)
OOwner information
UAuditing information

The default is DAT, which is data, attributes and timestamps.

/sec equals /copy:DATS, and /copyall equals /copy:DATSOU.

Mirror a folder and the risk of /mir

The /mir option mirrors a directory tree and is equivalent to /e plus /purge.

Microsoft says /purge deletes destination files and directories that no longer exist in the source.

That means a mirror removes anything in the destination that the source lacks.

Run the command with /l first, because that option lists what would happen without copying, deleting or timestamping anything.

Microsoft also notes that /mir with /e overwrites destination directory security settings.

Make large copies faster and safer

OptionWhat it does
/mt:<n>Multi-threaded copy with n threads, 1 to 128, default 8. Microsoft recommends /log for better performance, and /mt cannot be combined with /ipg or /efsraw.
/zRestartable mode, which resumes an interrupted copy instead of recopying the whole file.
/bBackup mode, which overrides ACLs that might block access.
/zbRestartable mode that falls back to backup mode if access is denied.
/jUnbuffered I/O, recommended for large files.
/ipg:<n>Inter-packet gap, to free bandwidth on slow lines.

If you only want to copy a handful of big files with no extras, our guide to copying large numbers of files quickly covers other approaches.

Choose which files to copy

OptionWhat it does
/xf <file>Excludes files matching names or paths; wildcards allowed.
/xd <dir>Excludes directories matching names or paths.
/xoExcludes source files older than the destination copy.
/xnExcludes source files newer than the destination copy.
/maxage:<n>Excludes files older than n days or a date.
/minage:<n>Excludes files newer than n days or a date.
/max:<n>Excludes files larger than n bytes.
/min:<n>Excludes files smaller than n bytes.

Move instead of copy

The /mov option moves files and deletes them from the source after copying.

The /move option does the same for files and directories.

Microsoft’s example moves files and subdirectories, leaves out empty ones and skips files older than seven days: robocopy C:\Users\Admin\Records D:\Backup /S /MAXAGE:7 /MOV /LOG:C:\Logs\Backup.log.

Skip files that already exist

Microsoft’s example for leaving existing files alone is robocopy C:\Source C:\Destination /XC /XN /XO.

Those switches exclude files with the same timestamp but a different size, source files newer than the destination copy, and source files older than it.

The result is that files already in the destination are skipped, regardless of age or modification.

Limit how much bandwidth a copy uses

Microsoft’s example robocopy C:\Records D:\Backup /iorate:1m limits I/O to 1 MB per second.

The /iomaxsize, /iorate and /threshold options control throttling.

Microsoft says the minimum throttled I/O bandwidth is 524288 bytes, even if you specify a lower value.

Save a job and watch a folder

OptionWhat it does
/save:<jobname>Saves parameters to a job file; put all copy, retry and logging options before this switch.
/job:<jobname>Loads parameters from a saved job file.
/quitExits after parsing the command line, which helps you check parameters.
/mon:<n>Monitors the source and runs again after n changes.
/mot:<m>Monitors the source and runs again after m minutes if changes are detected.

The /sj option copies junctions as junctions instead of following their targets.

The /sl option does not follow symbolic links and copies the link itself.

The /xj option excludes junction points, which are included by default.

When you use /purge or /mir on a volume root, Microsoft says robocopy now skips any files or directories named System Volume Information in the top-level source and destination.

Even so, avoid pointing a mirror at a drive root unless you have checked the destination first.

Retries and waiting

The /r:<n> option sets how many times robocopy retries a failed copy, and the default is 1,000,000.

The /w:<n> option sets the wait between retries in seconds, and the default is 30.

With those defaults, a locked file can hold up a job for a very long time, so set smaller values such as /r:2 /w:5.

Log the job

OptionWhat it does
/log:<file>Writes output to a log file, overwriting it.
/log+:<file>Appends to an existing log file.
/teeWrites to the console and the log file.
/npHides the progress percentage.
/etaShows the estimated time of arrival.
/lLists files only, without copying.

Microsoft recommends a log file for every job so you can verify the results.

Robocopy exit codes

CodeMeaning
0No files copied, no failures, no mismatches; files already exist in the destination.
1All files copied successfully.
2Extra files in the destination; no files copied.
3Some files copied, extra files present, no failures.
5Some files copied, some mismatched, no failures.
6Extra and mismatched files; no files copied.
7Files copied, with mismatches and extra files.
8Several files did not copy.

Microsoft states that any value of 8 or higher means at least one failure.

Official source

All options above come from Microsoft’s robocopy reference.

Its syntax notation is explained in the Command-Line Syntax Key.

Leave a Reply

Your email address will not be published. Required fields are marked *