Robocopy Command is usually used on Windows to copy files and directories from a location to another. Aside from that, this one also prints a detailed report of the copy operation. In this page, you can find the Robocopy Command syntax and examples.
Robocopy source destination [file [file]…] [option]
Source: Source directory (drive:\path or \\server\share\path).
Destination: Destination directory (drive:\path or \\server\share\path).
File: File(s) to copy (names/wildcards: default is “*.*”).
Copy options:
- /S: It copies subdirectories, but not the empty ones.
- /E: It copies subdirectories, including the empty ones.
- /LEV:n: It only copies the top n levels of the source directory tree.
- /Z: It copies files n the restartable mode.
- /B: It copies files in backup mode.
- /ZB: It uses restartable mode. If the access is denied, use backup mode.
- /EFSRAW: It copies all encrypted files in EFS RAW mode.
- /COPY:copyflag[s]: What to COPY for files (default is /COPY:DAT).
(copyflags: D means Data, A means Attributes, T means Timestamps).
(S means Security means NTFS ACLs, O means Owner info, U means aUditing info).
- /DCOPY:T: It copies the directory timestamps.
- /SEC: It copes files with security (equivalent to /COPY:DATS).
- /COPYALL: It copies all file info (equivalent to /COPY:DATSOU).
- /NOCOPY: It copies no file info (useful with /PURGE).
- /SECFIX: It fixes the file security on all files, including the skipped ones.
- /TIMFIX: It fixes files on all files, including the skipped ones.
- /PURGE: It deletes the dest files or dirs that no longer exist in the source.
- /MIR: It minors a directory tree (equivalent to /E plus /PUDGE).
- /MOV: It moves files (delete form the source after copying).
- /MOVE: It moves files and dirs. (delete from the source after copying).
- /A+:[RASHCNET]: It adds the given attributes to the copied files.
- /A-:[RASHCNET]: It removes the given attributes from the copied files.
- /CREATE: It creates the directory tree and zero-length files only.
- /FAT: It creates destination files using 8.3 FAT file names only.
- /256: Turn off very long path (> 256 characters) support.
- /MOT:n: It monitors sources; run again when more than n changes are seen.
- /MOT:m: Monitor source; run again in m minutes time, if changed.
- /RH:hhmm-hhmm: It runs hours – times when the new copies may be started.
- /PF: It checks run hours on a per file (not per pass) basis.
- /IPG:n: Inter=packet gap (ms), to the free bandwidth on slow lines.
- /SL: It copies symbolic links versus the target.
- /MT[:n]: DO some threaded copies with n threads (default 8). N has to be at least 1 and not greater compared to 128. This one is incompatible with the /IPG and /EFSRAW options. Redirect the output using /LOG option or the better performance.
File Selection Options:
- /A: It copies only the files with the archive attribute package.
- /M: It copies only the files with the archive attribute and reset it.
- /IA:[RASHCNETO]: It includes only the files with any of the given attributes package.
- /XA:[RASHCNETO]: It excludes files with any of the given attributes package.
- /XF file [file]…: It excludes files matching given names or paths or wildcards.
- /XD dirs. [dirs.]…: It excludes directories matching given names or paths.
- /XC: It excludes changed files.
- /XN: It excludes newer files.
- /XO: It excludes older files.
- /XX: It excludes extra files and directories.
- /XL: It excludes lonely files and directories.
- /IS: It includes the same files.
- /IT: It includes tweaked files.
- Etc.
Retry Options:
- /R:n: It is the numbers of retries on failed copies: default 1 million.
- /W:n: It is the wait time between retries: default is 30 seconds.
- /REG: It saves /R:n and /W:n in the registry as default settings.
- /TBD: It waits for sharenames to be defined (retry error 67).
Logging Options:
- /L: It lists only, does not copy, timestamp or delete any files.
- /X: It reports all extra files, not only the chosen ones.
- /V: It produces verbose output, displaying skilled files.
- /TS: It includes source file timestamps in the output.
- /FP: It includes the full pathname of files in the output.
- /BYTES: It prints sizes as bytes.
- /ETA: It shows estimated time of arrival of copied files.
- /LOG:file: It is the output status to LOG file (overwrite existing log).
- /LOG+:file: It is the output status to LOG file (append existing log).
- /UNILOG:file: It is the output status to LOG file as UNICODE (overwrite existing log).
- Etc.
Job Options:
- /JOB:jobname: It takes parameters from the named job file.
- /SAVE:jobname: It saves parameters to the named job file.
- /QUIT: It quits after processing the command line to view parameters.
- /IF: It includes the following files.
- Etc.
Robocopy examples:
The first example is robocopy c:\hope c:\hope2 *.txt. In this example, any .txt file will be copied from the hope directory into the hipe2 directory. Every time you want to copy one or more files and not a full directory the file has to be specified after the destination directory.
The second example is robocopy c:\hope c:\hope2. In this one, the robocopy command will copy all files (not directories) in the hope directory to the hope2 directory.
The third one is robocopy c:\hope c:\hope2 /e. In this one, all files and folders, including the empty ones, are copied from the hope directory to the hope2 directory.
The fourth one is robocopy c:\hope c:\hope2 /MIR. This one mirrors what is in c:\hope into c:\hope2 and cleans up any files in the hope2 directory that do not exist in the hope directory. You can use the /mir which switches deliberately since it deletes files that do not match in the destination directory.
The fifth one is robocopy \\computer\hope C:\hope2. This one will copy any of the files in the hope directory on the network computer named computer to the current computer hope2 directory.