
The robocopy
command (Robust File Copy) is a powerful utility in Windows that allows for fast and reliable copying or moving of files and directories. Unlike the basic copy
or xcopy
commands, robocopy
includes error handling and retry capabilities, making it ideal for network transfers and large-scale backups where reliability is critical.
What is the robocopy
Command?
robocopy
(Robust File Copy) is a command-line utility in Windows designed for copying and moving files or directories with advanced features. It supports network file transfers, directory mirroring, and can resume interrupted copies, making it a go-to tool for backup and synchronization tasks.
Key Uses of the robocopy
Command
- File and Folder Backup: Ideal for synchronizing directories or performing differential backups.
- Network File Transfers: Efficiently copy files across networks, with the ability to resume if interrupted.
- Directory Mirroring: Create an exact copy of a source directory, including all subdirectories and files.
How to Use the robocopy
Command
The robocopy
command requires you to specify the source and destination directories. You can also apply various options to control how the copy operation is performed.
Basic Syntax
robocopy <source> <destination> [<file>] [<options>]
Parameter | Description |
---|---|
<source> | Path to the source directory. |
<destination> | Path to the destination directory. |
<file> | (Optional) Specify the file(s) to copy. If omitted, defaults to *.* . |
<options> | Options to control the copy process (see below). |
Key Options
Option | Description |
---|---|
/s | Copies subdirectories, but excludes empty ones. |
/e | Copies all subdirectories, including empty ones. |
/mir | Mirrors the source and destination directories. Deletes files not present in the source. |
/z | Enables restartable mode, allowing copies to resume if interrupted. |
/b | Runs in backup mode to copy files. |
/copyall | Copies all file attributes (data, attributes, timestamps, ACLs, owner, etc.). |
/sec | Copies security information (ACLs). |
/purge | Deletes destination files that no longer exist in the source. |
/mov | Moves files by copying and deleting from the source. |
/mt[:n] | Enables multi-threaded copying (default is 8 threads). Specify n for custom threads. |
/log:<file> | Creates a log file of the copy operation. |
Examples
- Basic Directory Copy
robocopy C:\SourceFolder C:\DestinationFolder
Explanation: Copies all files from C:\SourceFolder
to C:\DestinationFolder
. Subdirectories are not copied by default.
- Copy with Subdirectories
robocopy C:\SourceFolder C:\DestinationFolder /e
Explanation: Copies all files and subdirectories, including empty directories, from C:\SourceFolder
to C:\DestinationFolder
.
- Restartable Network Copy
robocopy C:\SourceFolder C:\DestinationFolder /z
Explanation: Copies files with the ability to resume if interrupted (useful for network transfers).
- Directory Mirroring
robocopy C:\SourceFolder C:\DestinationFolder /mir
Explanation: Mirrors C:\SourceFolder
to C:\DestinationFolder
. Deletes any files in the destination that are not in the source.
- Copy with Security Information
robocopy C:\SourceFolder C:\DestinationFolder /sec
Explanation: Copies files along with their security information (ACLs).
Use Cases for the robocopy
Command
- Large-scale Backups: Useful for copying large datasets across servers or for creating backups. The tool’s error handling and retry mechanism ensure reliable transfers.
- File Synchronization: Keeps files in two directories synchronized, ensuring that the destination directory always matches the source.
- Directory Mirroring: Ideal for server backup or restoration processes where exact replicas of directories are required.
Tips and Precautions When Using the robocopy
Command
- Be Cautious with
/mir
: The/mir
option deletes files in the destination that no longer exist in the source, so use it carefully to avoid accidental data loss. - Monitor Network Load: For large file transfers over networks, be aware of potential network congestion. Consider using the
/ipg
option to introduce delays between packets and reduce the impact on the network. - Log Your Operations: Use the
/log
option to create a detailed log file of yourrobocopy
operations, helpful for tracking errors or reviewing actions later.
Conclusion
The robocopy
command is a powerful and reliable tool for copying or moving files and directories in Windows. Its advanced features, such as restartable copying, directory mirroring, and security attribute preservation, make it ideal for both small and large-scale operations. Whether you’re performing backups, synchronizing files, or transferring data over a network, robocopy
can streamline the process with its extensive options.

Thank you for reading!
Comments