23/08/2005
In the realm of digital data management, the simple act of copying files can quickly become a complex and time-consuming chore, especially when dealing with large volumes of data, intricate directory structures, or unreliable network connections. While Windows File Explorer offers basic copy-and-paste functionality, it often falls short for more demanding tasks. This is where Robocopy, or "Robust File Copy," steps in as an indispensable command-line utility built directly into Windows. Designed for resilience and versatility, Robocopy goes far beyond standard copying, offering features that ensure data integrity, facilitate automated backups, and significantly boost transfer speeds, making it a favourite among IT professionals and savvy users alike.

Robocopy's primary function is to copy file data from one location to another, but its true power lies in its extensive array of options. Unlike a basic copy operation, Robocopy is designed to be robust, meaning it can handle network interruptions, resume transfers, and manage file attributes, permissions, and timestamps with granular control. This makes it ideal for tasks ranging from routine backups and server migrations to synchronising large datasets across different storage mediums.
- Understanding Robocopy Syntax and Basic Usage
- Essential Robocopy Copy Options for Enhanced Control
- Advanced File Selection and Filtering
- Ensuring Reliability: Retry and Throttling Options
- Logging and Output Management
- Job Management and Automation
- Robocopy vs. Standard Copy Methods and Alternatives
- Practical Examples and Common Scenarios
- Understanding Robocopy Exit Codes
- Troubleshooting and Best Practices
- Frequently Asked Questions (FAQs)
Understanding Robocopy Syntax and Basic Usage
At its core, Robocopy operates using a straightforward syntax: robocopy <source> <destination> [<file>[ ...]] [<options>]. The <source> specifies the path to the directory you wish to copy from, while <destination> defines where the files will be copied to. You can optionally specify particular files or use wildcard characters (* or ?) to select multiple files. If no file is specified, *.* is used by default, copying all files.
For instance, to copy a file named yearly-report.mov from c:\reports to a file share \\marketing\videos, enabling multi-threading for higher performance and the ability to restart the transfer if interrupted, you would type:
robocopy c:\reports "\\marketing\videos" yearly-report.mov /mt /zIt's crucial to note that if any data is copied from the root of a device, the destination directory adopts "hidden" and "system" attributes during the copy process, which is an important detail for administrators.
Essential Robocopy Copy Options for Enhanced Control
Robocopy's versatility stems from its wide range of copy options, allowing precise control over how files and directories are handled during transfer. Here’s a breakdown of some fundamental and frequently used options:
/s: Copy Subdirectories (excluding empty ones). This option is perfect for copying directory trees while omitting any folders that contain no files./e: Copy Subdirectories (including empty ones). If maintaining the exact directory structure, including empty folders, is critical,/eis your go-to./z: Copy in Restartable Mode. This is a lifesaver for large files or unstable connections. If a copy operation is interrupted, Robocopy can resume from where it left off, saving significant time and bandwidth by not recopying the entire file./b: Copy in Backup Mode. This powerful option allows Robocopy to override file and folder permission settings (ACLs) that might otherwise block access, making it invaluable for backup scenarios where standard access is restricted./zb: Restartable Mode with Backup Fallback. Combines the benefits of/zand/b. It attempts to copy in restartable mode and switches to backup mode if access is denied./j: Unbuffered I/O. Recommended for very large files, this option uses unbuffered I/O, which can improve performance by bypassing the file system cache./copy:<copyflags>: Specify File Properties to Copy. This allows you to select precisely which file properties are transferred. The default isDAT(Data, Attributes, Time stamps). Other flags includeS(NTFS access control list/ACL),O(Owner information), andU(Auditing information). For example,/copy:DATSwill copy data, attributes, timestamps, and security./dcopy:<copyflags>: Specify Directory Properties to Copy. Similar to/copybut for directories. Default isDA(Data and Attributes)./copyall: Copy All File Information. Equivalent to/copy:DATSOU, ensuring data, attributes, timestamps, security, owner, and auditing information are all transferred./nocopy: Copy No File Information. Useful when combined with/purge, allowing deletions without copying file data./sec: Copy Files with Security. Equivalent to/copy:DATS./secfix: Fix File Security on All Files. Even on skipped files, this ensures ACLs are corrected. Note that it requires specifying the type of security info to copy (e.g.,/copyall,/copy:o,/copy:s,/copy:u, or/sec)./timfix: Fix File Times on All Files. Corrects timestamps even for skipped files.
Synchronisation and Movement Options
Beyond simple copying, Robocopy offers powerful synchronisation and movement capabilities:
/purge: Delete Destination Files/Directories Not in Source. This option removes files and directories from the destination that no longer exist in the source, effectively cleaning up the destination to match the source./mir: Mirror a Directory Tree. This is one of Robocopy's most potent features, equivalent to combining/e(copy all subdirectories, including empty ones) and/purge. It creates an exact replica of the source tree at the destination, deleting anything in the destination that isn't in the source. Use this with extreme caution, as it can lead to data loss if not fully understood./mov: Move Files. Copies files and then deletes them from the source./move: Move Files and Directories. Copies files and directories, then deletes them from the source.
Attribute Management and Special Copy Modes
/a+:[RASHCNET]//a-:[RASHCNETO]: Add/Remove Attributes. Allows setting or clearing specific attributes (Read-only, Archive, System, Hidden, Compressed, Not content indexed, Encrypted, Temporary, Offline) on copied files./create: Create Directory Tree and Zero-Length Files Only. Useful for pre-creating a directory structure without copying file data./fat: Create 8.3 FAT File Names. For compatibility with older file systems./256: Turn Off Long Path Support. Restricts paths to 256 characters, which can be useful for compatibility but generally not recommended for modern systems./efsraw: Copy Encrypted Files in EFS RAW Mode. Preserves encryption on EFS-encrypted files.
Advanced File Selection and Filtering
Robocopy provides granular control over which files and directories are included or excluded from the copy operation:
/a//m: Archive Attribute Based Copy./acopies only files with the Archive attribute set./mdoes the same but also resets the Archive attribute on the source files, useful for incremental backups./ia:[RASHCNETO]//xa:[RASHCNETO]: Include/Exclude by Attribute. Filters files based on specific attributes./xf <filename>[ ...]: Exclude Files. Excludes files matching specified names or wildcards./xd <directory>[ ...]: Exclude Directories. Excludes directories matching specified names or paths./xc: Exclude Changed Files. Excludes files with the same timestamp but different sizes./xn: Exclude Newer Files. Skips source files newer than the destination./xo: Exclude Older Files. Skips source files older than the destination./xx: Exclude Extra Files. Prevents deletion of files in destination not present in source./xl: Exclude "Lonely" Files. Skips files present in source but not destination, preventing new files from being added to the destination./im: Include Modified Files. Copies files where only the MFT (Master File Table) timestamp differs, even if content/size is the same. This can be critical for ensuring all metadata changes are replicated./is: Include Same Files. Forces copying of files that are identical in name, size, times, and all attributes./it: Include "Tweaked" Files. Copies files with the same name, size, and times, but different attributes./max:<n>//min:<n>: Max/Min File Size. Excludes files larger or smaller than a specified size in bytes./maxage:<n>//minage:<n>: Max/Min File Age. Excludes files older or newer than a specified number of days or a YYYYMMDD date./maxlad:<n>//minlad:<n>: Max/Min Last Access Date. Excludes files based on their last access date./xj//xjd//xjf: Exclude Junction Points. Prevents Robocopy from following and copying the contents of junction points (soft-links) for files or directories, or both./sl: Copy Symbolic Links. Creates a new symbolic link at the destination instead of copying the target's content.
Ensuring Reliability: Retry and Throttling Options
Robocopy's resilience is further bolstered by its retry and throttling mechanisms, crucial for network operations and resource management:
/r:<n>: Number of Retries. Specifies how many times Robocopy will attempt to copy a failed file. The default is a very high 1,000,000, which you'll almost certainly want to reduce./w:<n>: Wait Time Between Retries. Defines the delay in seconds between retries. Default is 30 seconds. A combination like/r:5 /w:5means 5 retries with a 5-second wait between each./reg: Save Retry Settings to Registry. Saves the/rand/wvalues as default settings for future Robocopy operations./tbd: Wait for Share Names to Be Defined. Useful when copying to network shares that might not be immediately available./lfsm[:<n>[kmg]]: Low Free Space Mode. A critical feature for managing disk space on the destination. Robocopy will pause copying if it detects that a file transfer would cause the destination volume's free space to fall below a specified "floor" value. If no value is given, the floor defaults to 10% of the destination volume's size. This is particularly useful for targets with cloud tiering. Note that/lfsmis incompatible with/mtand/efsraw./iomaxsize:<n>[kmg]//iorate:<n>[kmg]//threshold:<n>[kmg]: I/O Throttling. These options allow you to limit the maximum I/O bandwidth Robocopy uses, specified in kilobytes, megabytes, or gigabytes per second. This is invaluable for preventing Robocopy from saturating network connections or disk I/O, allowing other system processes to function normally./thresholdsets a minimum file size for throttling to engage, ensuring small files aren't unnecessarily delayed.
Logging and Output Management
Understanding what Robocopy does during a transfer is vital for verification and troubleshooting. Its logging options are comprehensive:
/l: List Only. Performs a dry run, listing files that would be copied, deleted, or timestamped without actually performing any operations. Essential for testing complex commands before execution./v: Verbose Output. Provides more detailed information, including skipped files./ts: Include Source File Timestamps. Adds the source file's last modified time to the output./fp: Include Full Path Names. Displays the complete path for each file in the output./bytes: Print Sizes as Bytes. Displays file sizes in bytes rather than a more readable format./ns//nc//nfl//ndl: Suppress Output Details. These options allow you to minimise log output by not logging file sizes, file classes, file names, or directory names, respectively. This can significantly speed up the copy process, especially with the multi-threaded option./np: No Progress. Suppresses the display of the progress percentage during the copy operation./eta: Show Estimated Time of Arrival. Displays an estimated time until completion for copied files./log:<logfile>//log+:<logfile>: Write to Log File./logoverwrites an existing log file, while/log+appends to it. This is highly recommended for auditing and troubleshooting./unilog:<logfile>//unilog+:<logfile>: Write Unicode Log File. Same as above but writes in Unicode text, useful for file names with special characters./tee: Output to Console and Log File. Displays status output in the console window while also writing it to a log file./njh//njs: No Job Header/Summary. Suppresses the Robocopy header and job summary statistics from the output, useful for scripting./unicode: Display Unicode Text. Forces the status output to be displayed as Unicode text.
Job Management and Automation
For recurring tasks or complex configurations, Robocopy offers job options:
/job:<jobname>: Load Parameters from Job File. Executes a Robocopy job using parameters saved in a named job file (.RCJextension)./save:<jobname>: Save Parameters to Job File. Saves the current command-line parameters to a job file. This must be the last option in the command./mon:<n>: Monitor Source for Changes. Robocopy stays running and re-runs the copy operation when more thannchanges are detected in the source directory./mot:<m>: Monitor Source by Time. Robocopy stays running and re-runs the copy operation inmminutes if changes are detected. This continues until manually terminated (Ctrl+C)./rh:hhmm-hhmm: Run Hours. Specifies a time window during which new copies can be started. If launched outside this window, Robocopy pauses until the next eligible time./pf: Per File Run Hours Check. Checks run hours for each file, not just per pass.
Robocopy vs. Standard Copy Methods and Alternatives
When considering Robocopy, it's natural to compare it with simpler methods or other tools. The primary distinction between Robocopy and standard "copy-paste" or even the older XCOPY command is its robustness. Robocopy excels in handling errors gracefully, resuming transfers, and offering granular control over file attributes and permissions. Standard methods often fail outright on network glitches or permission issues, requiring a complete restart.
While the provided information also touches upon rsync (a popular utility primarily for Unix-like systems, though available on Windows via Cygwin or WSL), the key difference lies in their native environments and feature sets. rsync is renowned for its delta-transfer algorithm, which only sends the differences between files, making it incredibly efficient over slow links. Robocopy, while not having a delta-transfer algorithm for file *content* differences, achieves efficiency by only copying files that have different timestamps or sizes by default, and by offering multi-threading for parallel transfers.

Robocopy is typically faster for local transfers or within a fast LAN due to its native Windows integration and multi-threading capabilities. For WAN transfers or highly granular synchronisation based on file content, rsync might offer advantages. However, for most Windows users, Robocopy is the built-in, powerful, and sufficient solution.
Performance Optimisation
Achieving optimal performance with Robocopy involves leveraging its specific switches:
/mt[:n]: Multi-threaded Copying. This is a game-changer for speed. By default, Robocopy uses 8 threads, but you can increase this to up to 128 (e.g.,/mt:32). This allows multiple files to be copied simultaneously, significantly reducing overall transfer time. However, be mindful that higher thread counts can increase resource usage (CPU, RAM, network bandwidth). This option is incompatible with/ipgand/efsraw./ipg:<n>: Inter-Packet Gap. Specifies a delay in milliseconds between each 64KB packet of data. This is useful for freeing bandwidth on slow network lines, preventing Robocopy from monopolising the connection./nooffload: Disable Windows Copy Offload. Sometimes, disabling the Windows Copy Offload mechanism can improve performance, especially with certain storage configurations./compress: Request Network Compression. New in Windows Server 2020 and backported to Windows 10/Server 2019, this requests SMB network compression during transfer if applicable, which can speed up transfers over slow links./noclone: Don't Attempt Block Cloning. Prevents Robocopy from attempting block cloning, an optimisation that can sometimes cause issues or be slower in specific scenarios.
To further speed up copies, especially when dealing with many small files, consider minimising log output using options like /ns, /nc, /nfl, and /ndl, as logging itself consumes resources.
Practical Examples and Common Scenarios
Let's look at some practical applications of Robocopy, building on the provided examples:
Example 1: Basic Backup of User Records
To copy all files and subdirectories, including empty ones, from C:\Users\Admin\Records to D:\Backup, ensuring robust operation with backup mode and logging:
robocopy C:\Users\Admin\Records D:\Backup /E /ZB /LOG:C:\Logs\Backup.logHere, /E ensures all subdirectories (even empty ones) are copied. /ZB provides restartable mode with a fallback to backup mode for permissions, and /LOG creates a log file for review.
Example 2: Mirroring a Directory for Exact Synchronisation
To mirror the contents of C:\Users\Admin\Records to D:\Backup, deleting any files in the destination not present in the source, with limited retries:
robocopy C:\Users\Admin\Records D:\Backup /MIR /R:2 /W:5 /LOG:C:\Logs\Backup.logThe /MIR option is critical here, making the destination an exact duplicate of the source. /R:2 /W:5 sets retries to 2 with a 5-second wait, preventing endless retries on persistent errors.
Example 3: High-Performance Multi-threaded Copy
To copy all files and subdirectories (excluding empty ones) while retaining file data, attributes, and timestamps, utilising 16 multi-threaded operations:
robocopy C:\Users\Admin\Records D:\Backup /S /COPY:DAT /MT:16 /LOG:C:\Logs\Backup.log/S copies subdirectories but skips empty ones. /COPY:DAT ensures data, attributes, and timestamps are preserved. /MT:16 enables 16 parallel threads for faster copying.
Example 4: Moving Older Files to Archival Storage
To move files and subdirectories (excluding empty ones) from C:\Users\Admin\Records to D:\Backup, specifically excluding files newer than 7 days (i.e., moving files older than 7 days):
robocopy C:\Users\Admin\Records D:\Backup /S /MAXAGE:7 /MOV /LOG:C:\Logs\Backup.log/MAXAGE:7 ensures only files older than 7 days are considered, and /MOV performs a move operation, deleting from the source after successful copy.

Example 5: Limiting Network Bandwidth
To copy all files and subdirectories from C:\Records to D:\Backup while limiting the I/O rate to 1 megabyte per second:
robocopy C:\Records D:\Backup /iorate:1mThis ensures the copy operation doesn't consume all available network bandwidth, crucial in shared environments.
Understanding Robocopy Exit Codes
After a Robocopy operation completes, it returns an exit code, which is a numerical value indicating the outcome. Understanding these codes is essential for scripting and automation, as they allow you to determine if the operation was successful or encountered issues. Any value equal to or greater than 8 indicates that there was at least one failure during the copy operation.
| Value | Description |
|---|---|
| 0 | No files copied, no failures, no mismatches. Files already exist in destination. |
| 1 | All files copied successfully. |
| 2 | Some additional files in destination not in source. No files copied. |
| 3 | Some files copied. Additional files present. No failure. |
| 5 | Some files copied. Some files mismatched. No failure. |
| 6 | Additional and mismatched files exist. No files copied, no failures. |
| 7 | Files copied, a file mismatch was present, and additional files were present. |
| 8+ | At least one failure occurred during the copy operation. |
Troubleshooting and Best Practices
Despite its robustness, Robocopy operations can encounter issues. Here are some common points and best practices:
- Access Denied (Error 5): This usually indicates file/folder or share permissions are preventing the copy. Either adjust permissions or use
/b(backup mode) or/zb. Running Robocopy under a non-administrator account requires specific privileges likeSeBackupPrivilege. - Long File Names: Robocopy supports UNC paths and long pathnames (over 256 characters). While it can copy them, accessing these files later with Windows Explorer might be problematic. Choosing shorter destination paths can mitigate this.
- Junction Points and Symbolic Links: By default,
/Scopies the *contents* of junction points. Use/XJ,/XJD, or/XJFto exclude them from the source. Be aware that/PURGEor/MIRcan follow and delete contents of junction points in the destination if not careful./SLcopies file symbolic links themselves, not their targets. - Deduplicated Files (Server 2016+): When mirroring a system drive, Robocopy in backup mode (
/Bor/ZB) might attempt to delete deduplicated files from\System Volume Information. Exclude this directory with/XDto avoid issues. - Large File Copy Stalling: When copying files larger than 2GB from certain iSCSI/SAN volumes, the operation might fill RAM and stall, often related to write-through caching on RAID controllers. Using
/IPGor alternative utilities like TeraCopy (which uses larger blocks) might help. - FAT Filenames with Long Names: If
/FATis used and short filenames match existing long filenames in the destination, the files will be replaced but retain their old long filenames, which can lead to inconsistencies. - Locked Files: Robocopy cannot copy files locked by other applications. Using
/R:0will skip locked files, speeding up the process, or consider using Volume Shadow Copy Service (VSS) tools likeDISKSHADOWto create a snapshot first, then copy from the snapshot. - NTFS Permissions: Robocopy copies ACLs for files and directories. However, it won't copy *changes* to ACLs unless the file itself has changed. Use
/SECor/SECFIXto force ACL updates even on unchanged files/folders. - Log File Destination: Ensure the log file's destination directory exists; Robocopy will create the log file but not the directory.
- PowerShell Quoting: When running Robocopy commands within PowerShell, be mindful of how PowerShell handles quotation marks, as it can sometimes lead to "invalid parameter" errors. Using a batch file or the latest PowerShell versions can mitigate this.
Frequently Asked Questions (FAQs)
Q: Can Robocopy be used for continuous backups?
A: Yes, with the /MON:n (monitor changes) or /MOT:m (monitor by time) switches, Robocopy can stay resident and perform incremental copies automatically when changes are detected or after a specified time interval. This enables a near-continuous backup solution.
Q: What is the main benefit of using /MIR?
A: The /MIR (mirror) switch ensures the destination directory becomes an exact replica of the source. This is incredibly powerful for synchronisation, as it not only copies new and changed files but also *deletes* files from the destination that are no longer present in the source. This keeps the destination perfectly in sync.
Q: How can I speed up Robocopy for large transfers?
A: The most significant speed improvement comes from using the /MT:n (multi-threaded) option, which allows parallel file copying. Increasing n (number of threads) can help, but test to find the optimal value for your system and network. Additionally, minimising log output (e.g., /nfl, /ndl) and using unbuffered I/O (/j for large files) can also boost performance.

Q: Can Robocopy copy open or locked files?
A: No, Robocopy natively cannot copy files that are exclusively locked by other applications. For copying open files, you would typically need to use the Volume Shadow Copy Service (VSS) (e.g., via DISKSHADOW or similar tools) to create a snapshot of the volume, and then use Robocopy to copy from that snapshot.
Q: What does "restartable mode" (/Z) mean?
A: Restartable mode means that if a file transfer is interrupted (e.g., due to a network disconnection), Robocopy can resume copying the file from the point of interruption rather than starting the entire file transfer over again. This saves time and bandwidth, especially for very large files and unreliable connections.
Q: How do I ensure file permissions are copied correctly?
A: To copy file and folder permissions (NTFS ACLs), use the /COPY:DATS (or simply /SEC) option. To ensure all security information is copied, including owner and auditing, use /COPYALL. If you need to fix permissions on files that haven't changed, use /SECFIX in conjunction with a security copying option.
Q: Is there a graphical user interface (GUI) for Robocopy?
A: While Robocopy itself is a command-line tool, there are third-party GUI wrappers available that provide a user-friendly interface for configuring and running Robocopy commands. Microsoft also released a GUI for Robocopy as part of the Windows Server 2003 Resource Kit Tools, though it's quite old now.
Robocopy stands as a testament to the power of command-line utilities. Its comprehensive feature set, from granular control over file attributes to robust error handling and performance optimisation, makes it an indispensable tool for anyone managing data on Windows systems. By mastering its syntax and options, you can achieve highly efficient, reliable, and automated file management operations that far surpass the capabilities of standard copy methods.
If you want to read more articles similar to Mastering Robocopy: Your Ultimate File Copy Tool, you can visit the Automotive category.
