The Windows “Robust File Copy” utility for efficiently copying files and directories, with built-in retry, logging, and mirroring capabilities.
https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
https://www.pdq.com/blog/hitchhikers-guide-to-robocopy/
https://activedirectorypro.com/robocopy-examples/
The Windows “Robust File Copy” utility for efficiently copying files and directories, with built-in retry, logging, and mirroring capabilities.
By default, Robocopy skips copying existing files if the specific metadata of the files match.
/mir : Mirror the source directory tree to the destination (equivalent to /e + /purge):
/e : copies all subdirectories, including empty ones
/purge : deletes files/folders at the destination that no longer exist at the source
/sj : Copy NTFS junction points (“soft-links”) themselves rather than what they point to. This preserves the junction at the destination.
/sl : Copy symbolic links as links (don’t follow them and copy the target file/directory).
/mt:24 :Run the copy operation using 24 concurrent threads (range 1–128; default is 8), for higher throughput on multi-core systems. This switch cannot be combined with /ipg or /efsraw.
/J : unbuffered I/O (good for large files)
/R:<N> : to limit retries (default is 1 000 000)
/W:<S> : to set the wait time in seconds (default is 30)
/NJS : No Job Summary.
/NC : No Class – don’t log file classes.
/NFL : (No File List) Suppresses the per-file lines (e.g. “New File …”, “Copied …”). Benefit: Cuts down console I/O, often shaving 10–20 % off total runtime on large trees.
/NDL : (No Directory List) Suppresses the per-directory header lines. Benefit: Further reduces console chatter.
/NP : (No Progress) Suppresses the percentage-complete on each file. Drawback: You lose the “XX %” indicator
/NJH : (No Job Header) and /NJS (No Job Summary) Only affect the very first and very last block; negligible on runtime and you probably want at least the summary.
/NS (No Size) and /NC (No Class) Remove size and class columns from each line. If you’re suppressing file/directory lists anyway, these don’t help much.
/XD : ignore given types
/ETA : Show Estimated Time of Arrival of copied files.
Note:
Robocopy’s support for NTFS reparse-points (symbolic links and junctions) is a bit quirky:
- /SL only affects symbolic links (it tells RoboCopy to replicate the link itself rather than follow it).
- /SJ only affects junction points (ditto for directory-junction reparse points).
- If you use both /SL and /SJ, RoboCopy can still attempt to enumerate a link as a real folder—leading to that “ERROR 267: The directory name is invalid.”
Because of this, this errors can be ignored:
2025/05/15 12:09:11 ERROR 267 (0x0000010B) Copying Directory C:\redux-remember\ The directory name is invalid.
Bat file example:
@echo off
setlocal
:: Define the source and destination directories
set "src=%cd%"
set "dst=C:\TEMP"
echo Copying %src% to %dst%
:: Use robocopy to copy the contents
robocopy "%src%" "%dst%" /MIR /SJ /SL /MT:24 /J /R:0 /W:2 /NFL /NDL /ETA /NP /NC /XD "__pycache__" ".pnpm"
pause
endlocal