How to Use Robocopy
Robocopy, also known as Robust File Copy, is a powerful command-line directory replication tool developed by Microsoft. Unlike conventional file copiers like copy and xcopy, Robocopy is specifically designed to efficiently copy directories while preserving their original structure. With Robocopy, you can copy a single directory or recursively copy an entire directory and its subdirectories. It offers advanced features such as automatic resumption of file transfers in case of errors or network disruptions, as well as recovery from interrupted copying. Additionally, selective copying based on new or updated criteria is supported, making it a versatile tool for maintaining identical directory structures on a single computer or across multiple network locations.
- Source : Specifies the path to the source directory.
- Destination : Specifies the path to the destination directory.
- File : Specifies the file or files to be copied. You can use wildcard characters (* or ?), if you want.
- Options : Specifies options to be used with the robocopy command.
One notable feature of Robocopy is its intelligent handling of file copies. When a file exists both in the source and destination locations, Robocopy will only copy the file if the two versions have different time stamps or sizes. This time-saving approach is particularly advantageous when working with slow network links. Moreover, you can specify that copying should be restarted in case of a failure, further optimizing the process, especially when network links are unreliable.
Robocopy comes pre-installed in Windows operating systems such as Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10, and Windows Server, accessible through the command-line interface. It provides detailed reports of the copy operation and offers real-time progress monitoring of source and destination targets, ensuring comprehensive visibility into the copying process. With its robust and efficient features, Robocopy proves to be an indispensable tool for managing file replication tasks in diverse computing environments.
Robocopy and a Few Examples
How to copy content of a foler to another folderThe above command copy files from c:\temp\newtemp whose size is larger than 4kb (4096)
Copy files less tha specified sizeThe above command copy files from c:\temp\newtemp whose size is less than 5kb (5120)
Mirror FolderThe above command will mirror what is in c:\tempe into D:\backup\mis\dev and purge any files in the D:\backup\mis\dev directory that do not exist in the hope directory.
Use the /MIR switch carefully since it will be deleting files that do not match in the destination directory.
Copy from networkThe above example would copy any of the files in the temp directory on the network computer (\\SERVER\backup\temp) to the current computer D:\backup\mis\dev directory.
Copy a directory treeThe above command delete the content in the folder c:\temp\newtemp after copying the content to c:\temp\newtemp
Move the files older than specified daysThe above command move files over 10 days old, however the MOVE option will fail if any files are open and locked.
Copy files without overwriteThe above command copy files from source folder to destination folder without overwrite.
- /E makes Robocopy recursively copy subdirectories, including empty ones.
- /XC excludes existing files with the same timestamp, but different file sizes. Robocopy normally overwrites those.
- /XN excludes existing files newer than the copy in the source directory. Robocopy normally overwrites those.
- /XO excludes existing files older than the copy in the source directory. Robocopy normally overwrites those.
How to make robocopy silent in the command line
- NFL : No File List - don't log file names.
- NDL : No Directory List - don't log directory names.
- NJH : No Job Header.
- /NJS : No Job Summary.