Skip to content

/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

Criterionxcopyrobocopy
Copy a folder treexcopy src dst /e /irobocopy src dst /e
Mirror (delete extras in dst)no/mir (or /purge)
Retry on locked or busy filesno/r:N /w:S
Resume interrupted large filesno/z (restartable), /b (backup mode, admin)
Multithreadedno/mt[:N], default 8 threads
Only newer files/ddefault: skips files with the same size and time
Copy NTFS ACLs, owner/o /x/copy:DATSOU or /sec
Log fileno (redirect output)/log:file, /tee
Exit code0 ok, 1 no files, 2 Ctrl+C, 4 init error, 5 disk write errorbit flags, 8 or more is failure
Interactive promptsmay ask file or directory (F/D) and overwritenever prompts

Same tree, both tools

cmd
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-robocopy

Output

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.txt prompts for F/D; plain copy a.txt b.txt is simpler.

Sources