Robocopy command for copying files in windows

Robocopy command for copying files in windows

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

Syntax:

 

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

 

Mirror copy

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

 

Replicate access

/SEC option copies all the file access permissions to the destination folder also.

 robocopy D:sourcedata E:destinationdata /SEC

Robocopy command line reference

Copy options

/SCopy Subdirectories, but not empty ones.
/ECopy subdirectories, including Empty ones.
/LEV:nOnly copy the top n LEVels of the source directory tree.
/ZCopy files in restartable mode.
/BCopy files in Backup mode.
/ZBUse restartable mode; if access denied use Backup mode.
/EFSRAWCopy 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:TCOPY Directory Timestamps.
/SECCopy files with SECurity (equivalent to /COPY:DATS).
/COPYALLCOPY ALL file info (equivalent to /COPY:DATSOU).
/NOCOPYCOPY NO file info (useful with /PURGE).
/SECFIXFIX file SECurity on all files, even skipped files.
/TIMFIXFIX file TIMes on all files, even skipped files.
/PURGEDelete dest files/dirs that no longer exist in source.
/MIRMIRror a directory tree (equivalent to /E plus /PURGE).
/MOVMOVe files (delete from source after copying).
/MOVEMOVE 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.
/CREATECREATE directory tree and zero-length files only.
/FATCreate destination files using 8.3 FAT file names only.
/256Turn off very long path (> 256 characters) support.
/MON:nMONitor source; run again when more than n changes seen.
/MOT:mMOnitor source; run again in m minutes Time, if changed.
/RH:hhmm-hhmmRun Hours – times when new copies may be started.
/PFCheck run hours on a Per File (not per pass) basis.
/IPG:nInter-Packet Gap (ms), to free bandwidth on slow lines.
/SLCopy 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

/ACopy only files with the Archive attribute set.
/MCopy 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.
/XCeXclude Changed files.
/XNeXclude Newer files.
/XOeXclude Older files.
/XXeXclude eXtra files and directories.
/XLeXclude Lonely files and directories.
/ISInclude Same files.
/ITInclude Tweaked files.
/MAX:nMAXimum file size – exclude files bigger than n bytes.
/MIN:nMINimum file size – exclude files smaller than n bytes.
/MAXAGE:nMAXimum file AGE – exclude files older than n days/date.
/MINAGE:nMINimum file AGE – exclude files newer than n days/date.
/MAXLAD:nMAXimum Last Access Date – exclude files unused since n.
/MINLAD:nMINimum Last Access Date – exclude files used since n.
(If n < 1900 then n = n days, else n = YYYYMMDD date).
/XJeXclude Junction points. (normally included by default).
/FFTAssume FAT File Times (2-second granularity).
/DSTCompensate for one-hour DST time differences.
/XJDeXclude Junction points for Directories.
/XJFeXclude Junction points for Files.

Retry Options

/R:nNumber of Retries on failed copies: default 1 million.
/W:nWait time between retries: default is 30 seconds.
/REGSave /R:n and /W:n in the Registry as default settings.
/TBDWait for sharenames To Be Defined (retry error 67).

Logging Options

/LList only – don’t copy, timestamp or delete any files.
/XReport all eXtra files, not just those selected.
/VProduce Verbose output, showing skipped files.
/TSInclude source file Time Stamps in the output.
/FPInclude Full Pathname of files in the output.
/BYTESPrint sizes as bytes.
/NSNo Size – don’t log file sizes.
/NCNo Class – don’t log file classes.
/NFLNo File List – don’t log file names.
/NDLNo Directory List – don’t log directory names.
/NPNo Progress – don’t display percentage copied.
/ETAShow Estimated Time of Arrival of copied files.
/LOG:fileOutput status to LOG file (overwrite existing log).
/LOG+:fileOutput status to LOG file (append to existing log).
/UNILOG:fileOutput status to LOG file as UNICODE (overwrite existing log).
/UNILOG+:fileOutput status to LOG file as UNICODE (append to existing log).
/TEEOutput to console window, as well as the log file.
/NJHNo Job Header.
/NJSNo Job Summary.
/UNICODEOutput status as UNICODE.

Job Options

/JOB:jobnameTake parameters from the named JOB file.
/SAVE:jobnameSAVE parameters to the named job file.
/QUITQUIT after processing command line (to view parameters).
/NOSDNO Source Directory is specified.
/NODDNO Destination Directory is specified.
/IFInclude the following Files.

You can also download the command line reference and usage notes for Robocopy as a PDF file.

Leave a Reply

Top