/compare/cmd/xcopy-vs-robocopy
xcopy vs robocopy: which one to use for copying folders
verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
- tool
- Command Prompt (cmd)
- compares
- xcopy vs robocopy
Use robocopy for anything beyond a quick copy: it copies folder trees, can mirror a source (deleting extras in the destination), retries locked files, resumes large files in restartable mode, copies with several threads and writes a log. xcopy is the older tool; it copies trees too, but it has no mirror, no retry and no multithreading, and it can stop to ask whether a target is a file or a folder. Both ship with Windows.
Criterion by criterion
| Criterion | xcopy | robocopy |
|---|---|---|
| Copy a folder tree | xcopy src dst /e /i | robocopy src dst /e |
| Mirror (delete extras in dst) | no | /mir (or /purge) |
| Retry on locked or busy files | no | /r:N /w:S |
| Resume interrupted large files | no | /z (restartable), /b (backup mode, admin) |
| Multithreaded | no | /mt[:N], default 8 threads |
| Only newer files | /d | default: skips files with the same size and time |
| Copy NTFS ACLs, owner | /o /x | /copy:DATSOU or /sec |
| Log file | no (redirect output) | /log:file, /tee |
| Exit code | 0 ok, 1 no files, 2 Ctrl+C, 4 init error, 5 disk write error | bit flags, 8 or more is failure |
| Interactive prompts | may ask file or directory (F/D) and overwrite | never prompts |
Same tree, both tools
mkdir src\sub
> src\top.txt echo top
> src\sub\deep.txt echo deep
xcopy src dst-xcopy /e /i /q /y
echo xcopy: ERRORLEVEL=%ERRORLEVEL%
robocopy src dst-robocopy /e /nfl /ndl /njh /njs /np > nul
echo robocopy: ERRORLEVEL=%ERRORLEVEL%
dir /b /s dst-xcopy dst-robocopyOutput
2 File(s) copied xcopy: ERRORLEVEL=0 robocopy: ERRORLEVEL=1 /tmp/work/dst-xcopy/sub /tmp/work/dst-xcopy/top.txt /tmp/work/dst-xcopy/sub/deep.txt /tmp/work/dst-robocopy/sub /tmp/work/dst-robocopy/top.txt /tmp/work/dst-robocopy/sub/deep.txt
robocopy's 1 is success (files copied). xcopy's /i tells it that a missing destination is a folder; without it, xcopy asks Does dst specify a file name or directory name on the target (F = file, D = directory)?, which hangs unattended scripts.
When xcopy is still fine
- One-off copies at the prompt where you watch the result.
- Copying a single file to a new name:
xcopy a.txt b.txtprompts for F/D; plaincopy a.txt b.txtis simpler.
Sources
- learn.microsoft.comlearn.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy
- learn.microsoft.comlearn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
- learn.microsoft.comlearn.microsoft.com/en-us/troubleshoot/windows-server/backup-and-storage/return-codes-used-robocopy-utility
Related pages
codes · cmdrobocopy exit codes: 0, 1, 2, 3, 8 and 16 explainedrobocopy exit codes are bit flags: 1 copied, 2 extra files, 4 mismatches, 8 failures, 16 fatal error. Any code below 8 is success; treat 8 or more as failure.cheat sheets · cmdcmd cheat sheet: files, variables, batch syntax and network commandsCommand Prompt cheat sheet: files and folders, variables and substrings, if and for in batch files, plus ipconfig, netstat -ano, tasklist and systeminfo.errors · cmdThe process cannot access the file because it is being used by another process.Windows error 32: another program holds the file open without sharing. Find it with Resource Monitor or handle.exe, close it, then retry the del, move or copy.flags · cmdrobocopy /MIR: mirror a folder (and why it deletes files in the destination)robocopy /MIR mirrors a folder: it copies subfolders and deletes destination files missing from the source. Preview with /L, exit codes 1-3 and /E /PURGE.