Robocopy(Robust File Copy) is a useful windows command to copying files and directories from one place to another. It also displays complete information of the copy operation. The Robocopy commands and its usage as below.
- Copying File and Directories
- Moving Files and Directories
- Modification of Files attributes
- Mirror copy
- Replicate access
This is available in the following Microsoft operating systems as robocopy.exe.
- Windows NT (In resource kit)
- Windows 2000 (In resource kit)
- Windows Server 2008
- Windows Vista
- Windows 7
- Windows 8
- Windows 10
ROBOCOPY <source> <destination> [file…] [options]
Copying File and Directories
Copy all the files from directory to other. Doesn't include sub directories and sub directories files.
Robocopy D:sourcedata E:destinationdata
This command copies system files and hidden files too. Finally, display the copied information like below.
Total Copied Skipped Mismatch FAILED Extras
Dirs : 8 8 0 0 0 0
Files : 156 156 0 0 0 0
Bytes : 72.86 m 72.86 m 0 0 0 0
Times : 0:00:01 0:00:00 0:00:00 0:00:00
Speed : 75986285 Bytes/sec.
Speed : 4562.756 MegaBytes/min.
Ended : Fri Feb 05 12:17:14 2016
Copy all the files from directory to Other. Also Include sub directories and sub directories files.
Robocopy D:sourcedata E:destinationdata /S
This command Ignore the empty directory. Finally, display the summary like below.
Copy all the files from directory to other. Also Include sub directories, sub directories files and empty directories.
Robocopy D:sourcedata E:destinationdata /S /E
Moving Files and Directories
Move files and directories and delete source files after copying by adding /MOV
Robocopy D:sourcedata E:destinationdata /MOV /S /E
This command delete all directories files and sub directories files, not the directories.
Move files and directories and delete source files and directories after copying by adding /MOVE
Robocopy D:sourcedata E:destinationdata /MOVE /S /E
Note: MOVE option will fail if any files are open and locked
Move files over 14 days old.
Robocopy D:sourcedata E:destinationdata /MOVE /S /E /minage:14
Similarly you could use the below cases
/maxage: <N> maximum file age (to exclude files older than N days or date).
/minage: <N> minimum file age (exclude files newer than N days or date).
/maxlad: <N> maximum last access date (excludes files unused since N).
/minlad: <N> minimum last access date (excludes files used since N) If N is less than 1900, N specifies the number of days. Otherwise, N specifies a date in the format YYYYMMDD
Modify file attributes of the copied files
We can also change the attributes (system, hidden, readonly) of the copied files using robocopy command.
This command only change the attributes of the destination directory files, it does not change the source directory files.
For example to copy all files from source directory to destination directory and also set hidden attribute for all the files you can run the below command.
Robocopy /S /E /A+:H D:sourcedata E:destinationdata
Creates a replica of the source folder in the specified destination folder
Robocopy D:sourcedata E:destinationdata /MIR
This command also deletes any extra files that are present in the destination and are not present in source.
For example, If you want to delete all files in a directory 'D:filedir'
Create an empty directory 'D:emptydir' and execute the following command
Robocopy D:emptydir D:filedir /s /MIR
/SEC option copies all the file access permissions to the destination folder also.
robocopy D:sourcedata E:destinationdata /SEC
Robocopy command line reference
|/S||Copy Subdirectories, but not empty ones.|
|/E||Copy subdirectories, including Empty ones.|
|/LEV:n||Only copy the top n LEVels of the source directory tree.|
|/Z||Copy files in restartable mode.|
|/B||Copy files in Backup mode.|
|/ZB||Use restartable mode; if access denied use Backup mode.|
|/EFSRAW||Copy all encrypted files in EFS RAW mode.|
|/COPY:copyflag[s]||What to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).
|/DCOPY:T||COPY Directory Timestamps.|
|/SEC||Copy files with SECurity (equivalent to /COPY:DATS).|
|/COPYALL||COPY ALL file info (equivalent to /COPY:DATSOU).|
|/NOCOPY||COPY NO file info (useful with /PURGE).|
|/SECFIX||FIX file SECurity on all files, even skipped files.|
|/TIMFIX||FIX file TIMes on all files, even skipped files.|
|/PURGE||Delete dest files/dirs that no longer exist in source.|
|/MIR||MIRror a directory tree (equivalent to /E plus /PURGE).|
|/MOV||MOVe files (delete from source after copying).|
|/MOVE||MOVE files AND dirs (delete from source after copying).|
|/A+:[RASHCNET]||Add the given Attributes to copied files.|
|/A-:[RASHCNET]||Remove the given Attributes from copied files.|
|/CREATE||CREATE directory tree and zero-length files only.|
|/FAT||Create destination files using 8.3 FAT file names only.|
|/256||Turn off very long path (> 256 characters) support.|
|/MON:n||MONitor source; run again when more than n changes seen.|
|/MOT:m||MOnitor source; run again in m minutes Time, if changed.|
|/RH:hhmm-hhmm||Run Hours - times when new copies may be started.|
|/PF||Check run hours on a Per File (not per pass) basis.|
|/IPG:n||Inter-Packet Gap (ms), to free bandwidth on slow lines.|
|/SL||Copy symbolic links versus the target.|
|/MT[:n]||Do multi-threaded copies with n threads (default 8).
n must be at least 1 and not greater than 128.
This option is incompatible with the /IPG and /EFSRAW options.
Redirect output using /LOG option for better performance.
File Selection Options
|/A||Copy only files with the Archive attribute set.|
|/M||Copy only files with the Archive attribute and reset it.|
|/IA:[RASHCNETO]||Include only files with any of the given Attributes set.|
|/XA:[RASHCNETO]||eXclude files with any of the given Attributes set.|
|/XF file [file]...||eXclude Files matching given names/paths/wildcards.|
|/XD dirs [dirs]...||eXclude Directories matching given names/paths.|
|/XC||eXclude Changed files.|
|/XN||eXclude Newer files.|
|/XO||eXclude Older files.|
|/XX||eXclude eXtra files and directories.|
|/XL||eXclude Lonely files and directories.|
|/IS||Include Same files.|
|/IT||Include Tweaked files.|
|/MAX:n||MAXimum file size - exclude files bigger than n bytes.|
|/MIN:n||MINimum file size - exclude files smaller than n bytes.|
|/MAXAGE:n||MAXimum file AGE - exclude files older than n days/date.|
|/MINAGE:n||MINimum file AGE - exclude files newer than n days/date.|
|/MAXLAD:n||MAXimum Last Access Date - exclude files unused since n.|
|/MINLAD:n||MINimum Last Access Date - exclude files used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).
|/XJ||eXclude Junction points. (normally included by default).|
|/FFT||Assume FAT File Times (2-second granularity).|
|/DST||Compensate for one-hour DST time differences.|
|/XJD||eXclude Junction points for Directories.|
|/XJF||eXclude Junction points for Files.|
|/R:n||Number of Retries on failed copies: default 1 million.|
|/W:n||Wait time between retries: default is 30 seconds.|
|/REG||Save /R:n and /W:n in the Registry as default settings.|
|/TBD||Wait for sharenames To Be Defined (retry error 67).|
|/L||List only - don't copy, timestamp or delete any files.|
|/X||Report all eXtra files, not just those selected.|
|/V||Produce Verbose output, showing skipped files.|
|/TS||Include source file Time Stamps in the output.|
|/FP||Include Full Pathname of files in the output.|
|/BYTES||Print sizes as bytes.|
|/NS||No Size - don't log file sizes.|
|/NC||No Class - don't log file classes.|
|/NFL||No File List - don't log file names.|
|/NDL||No Directory List - don't log directory names.|
|/NP||No Progress - don't display percentage copied.|
|/ETA||Show Estimated Time of Arrival of copied files.|
|/LOG:file||Output status to LOG file (overwrite existing log).|
|/LOG+:file||Output status to LOG file (append to existing log).|
|/UNILOG:file||Output status to LOG file as UNICODE (overwrite existing log).|
|/UNILOG+:file||Output status to LOG file as UNICODE (append to existing log).|
|/TEE||Output to console window, as well as the log file.|
|/NJH||No Job Header.|
|/NJS||No Job Summary.|
|/UNICODE||Output status as UNICODE.|
|/JOB:jobname||Take parameters from the named JOB file.|
|/SAVE:jobname||SAVE parameters to the named job file.|
|/QUIT||QUIT after processing command line (to view parameters).|
|/NOSD||NO Source Directory is specified.|
|/NODD||NO Destination Directory is specified.|
|/IF||Include the following Files.|
You can also download the command line reference and usage notes for Robocopy as a PDF file.