Robocopy Usage and Examples

Problem:
How do I use robocopy to copy files from one directory to another?

Solution:
In its simplest implementation and to literally just copy files without any options you could just run the following:

Robocopy "<Path to your source folder>" "<Path to your destination folder>"

 

However some basic switches will make the copy process less troublesome. For instance you may want to retain the original permissions, copy subdirectories and include empty directories.  The below script will also set the number of retry times to 0, the number of seconds to wait between retries to 0 and specify a log path.

Robocopy /E /sec /R:0 /W:0 /log:"c:\logfile.log" "<Path to your source folder>" "<Path to your destination folder>"

 

You can also go one step further and throttle your robocopy transfers by using the /IPG switch. The general rule of thumb is that /IGP:750 will use around 1Mbps transfer rate as the below example shows.

Robocopy /E /sec /R:0 /W:0 /ipg:750 /log:"c:\logfile.log" "<Path to your source folder>" "<Path to your destination folder>"

 

Example using multi-threading:

Robocopy /E /sec /R:0 /W:0 /MT:32 /log:"c:\temp\logfile.log" "\\server\share" "E:\Temp"

 

Example copying a particular file with long file name and “.” and numbers in the file/folder name.

Robocopy /E /sec /R:0 /W:0 /MT:32 /log:"c:\temp\logfile.log" "D:\Folder01\Folder\Folder02\\"10.112.0.9"" "F:\Folder01\Folder\Folder02\\"10.112.0.9"" 10.112.0.9D2022-03-30T142214_48C6.somefile

 

Here is another example for a copy in restartable mode, using the default multithreading (8).

Robocopy /Z /E /sec /R:0 /W:0 /MT /log+:"E:\Robocopy_Logs\logfile.log" \\Folder1 \\Folder2

 

Here is an example where we only want to copy the root level folder and the folder structure below it (using Lev:1), but no files.

Robocopy /Z /e /R:0 /W:0 /MT /Lev:1 /SEC /log+:"E:\Robocopy_Logs\logfile.log" \\Folder1 \\Folder2 /XF *

 

The switches I have used above are:
/ipg:750    Throttles the transfer to 1Mbps transfer rate
/S                   Copy Subdirectories, but not empty ones
/E                   Copy subdirectories, including Empty ones
/SEC            Copy files with Security (equivalent to /COPY:DATS)
/R:0              Sets the retry count to 0
/W:0            Sets the wait time between retries to 0
/log:              Logs the transfer to the path specified
/MT32        Sets the Multi-Threading parameter to 32 (his drastically speeds up file transfers for many small files)
/Z                   Copy files in restartable mode

You should not use /S and /E in the same script for obvious reasons!

Leave a Reply

Your email address will not be published. Required fields are marked *