Copying files using the command prompt

Copying Files With Robocopy

Robocopy (Robust File Copy) is a powerful command-line tool in Windows used for advanced file and folder copying operations. Robocopy provides more control and flexibility compared to copy commands like ‘copy’ or ‘xcopy’. Robocopy has is really useful for tasks such as mirrioring directories, backing up files, or syncing files/folders between different locations. I will provide you with some basic examples on how to use Robocopy today.

Basic Robocopy command:

robocopy <source> <destination>

This command copies files and sub-directories from the source directory to the destination directory.

Example:

robocopy C:\SourceFolder D:\DestinationFolder

This command copies all files and sub-directories from ‘C:\SourceFolder’ to ‘D:\DestinationFolder’

Mirror a directory:

robocopy <source> <destination> /MIR

The ‘/MIR’ option mirrors the source directory to the destination directory, which means it copies files and sub-directories and also removes any files or directories in the destination that no longer exist in the source.

Example:

robocopy C:\SourceFolder D:\DestinationFolder /MIR

This commands mirrors ‘C:\SourceFolder’ to ‘D:\DestinationFolder’, copying any new or changing files and deleting any files or directories in the destination that don’t exist in the source.

Copy files in restartable mode:

robocopy <source> <destination> /Z

The ‘/Z’ option enables restartable mode, which allows the copying process to resume from the point of it was interrupted.

Example:

robocopy C:\SourceFolder D:\DestinationFolder /Z

Like the examples above this command copies files from ‘C:\SourceFolder’ to ‘D:\DestinationFolder’ but this time it’s in a restartable mode.

The last example for today is how to just copy new or changed files, which will prevent files in the destination directory from being overwritten. So only files that are newer or don’t exist are going to exist in the destination folder.

Copy only new or changed files:

robocopy C:\SourceFolders D:\DestinationFolder /XO

I will start adding some advanced methods I use Robocopy for in a production environment, but this tool is just so handy for even backing up personal computers to a NAS or other storage device. Thanks for reading and have a wonderful day!