Robocopy is a powerful, robust, and Windows-native command-line tool for copying files, folders, and even syncing directories β especially useful for backup, migration, or bulk copying.
β Robocopy Basics
robocopy [source] [destination] [/options]
π― Example: Copy a Folder and All Its Files
β Basic Copy (with subfolders)
robocopy "C:\SourceFolder" "D:\DestinationFolder" /E /COPY:DAT /R:10 /W:5
π Breakdown of Options
| Option | Description |
|---|---|
/E | Copy subdirectories and empty directories too. |
/COPY:DAT | Copy data, attributes, and timestamps β preserves file metadata. |
/R:10 | Retry up to 10 times if a file fails to copy. |
/W:5 | Wait 5 seconds between retries. |
/LOG+:C:\backup.log | Log output to a file β useful for debugging or tracking. |
/Z | Copy files even if theyβre open (useful for files being used by programs). |
π§© Example: Copy with Logging
robocopy "C:\SourceFolder" "D:\DestinationFolder" /E /COPY:DAT /R:10 /W:5 /LOG+:C:\backup.log
This logs the copy operation to
C:\backup.log.
π Example: Copy Without Overwriting
robocopy "C:\SourceFolder" "D:\DestinationFolder" /E /COPY:DAT /R:10 /W:5 /Z /COPY:DAT
This copies files without overwriting β if a file already exists, it will not overwrite it.
π Example: Copy with Overwrite (Default)
robocopy "C:\SourceFolder" "D:\DestinationFolder" /E /COPY:DAT /R:10 /W:5
This copies all files β and overwrites existing files.
π§ Pro Tips
- Use
/LOG+:C:\backup.logto track whatβs copied β very useful for debugging. - Use
/Zif youβre copying files that are being used (e.g., by a program). - Use
/COPY:DATto preserve file metadata (timestamps, permissions, etc.). - Use
/Eto copy empty directories too.
π Example: Copy a Folder with Logging
robocopy "C:\SourceFolder" "D:\DestinationFolder" /E /COPY:DAT /R:10 /W:5 /LOG+:C:\backup.log
π« Common Mistakes
- β
robocopy C:\Folder D:\Folderβ Wrong! You must specify the folder name. - β
robocopy C:\Folder\ D:\Folder\ /Eβ Wrong! You need to specify the folder name. - β
robocopy C:\Folder\ D:\Folder\ /E /Iβ Wrong! You need to specify the folder name.
β Correct: `robocopy “C:\Folder” “D:\
I hope this helps you as much as it has helped me with my Windows backups.
