Skip to content

Hitchhiker's Guide to Robocopy

Brock Bingham candid headshot
Brock Bingham|Updated July 9, 2024
Hitchhiker's Guide to Robocopy
Hitchhiker's Guide to Robocopy

Whether you’re a command-line fan or just really like having control over your file transfers, Robocopy is the way to go. In this guide, I’ll walk you through what Robocopy is, how to use it, and a few of its alternatives. I’ll leave you with a few Robocopy examples to help with the learning curve that is the command line.

What is Robocopy?

Robocopy, which stands for robust file copy (not robot copy, unfortunately), is a command-line utility that copies, replicates, or moves files and directories. It’s a far more robust alternative to Xcopy and essentially replaces Xcopy. Robocopy was initially released as part of the Windows NT 4.0 Resource Kit and has been integrated as a standard feature of Windows since Windows Vista and Windows Server 2008.

Why you should use Robocopy

While copying a few files here and there can be a simple undertaking, transferring mind-bogglingly large numbers of files or multiple folders across a network can get very complex very quickly. But to quote Douglas Adams, “Don't Panic,” because this exact scenario is what Robocopy was built to handle.

Robocopy has more options than you can shake a stick at. If you’re the type of person who buys a fully loaded car simply because it comes with all the options (even though you’ll never use half of them), then Robocopy is for you. You’ve got options for logging, scheduling, attributes, file name lengths, file types, excluding, including, file sizes, purging, and much, much more. You'll probably never use most of the options, but it’s comforting to know they’re there.

ConnectIcon CTA

Quick & easy Windows patch management

Unlock automated patching that's simple, secure, and pretty damn quick.

Robocopy switches

Let’s take a moment to really break down all the Robocopy switches. Switches in Robocopy (sometimes called parameters, arguments, or options) add to, modify, or extend a Robocopy command’s functionality.

If you ever want to view what additional switches can be set for a given command, simply enter the command followed by /?. For example, to return all the available options for Robocopy, run this in the Command Prompt.

robocopy /?

As you’ll see, this command returns a long list of available Robocopy switches, letting you copy files where, when, and how you want. To make this information a little easier to digest, I’ve listed all of the available parameters in this handy-dandy table. I’ve also included my own notes on each switch, detailing what they do since the included explanation from Microsoft could be considered lackluster at best.

Copy options

SwitchExplanation Notes
/Scopy Subdirectories, but not empty ones.Robocopy does not copy subdirectories by default.
/Ecopy subdirectories, including Empty ones.Same as /S, but it also copies empty subdirectories. Automatically adds /S into the command.
/LEV:nonly copy the top n LEVels of the source directory tree./LEV:1 copies only files from the root source folder. /LEV 2 copies the files in the root source as well as the first level of subdirectories and so on.
/Zcopy files in restartable mode.Allows Robocopy to pick back up where it left off if an error or connection drop is encountered.
/Bcopy files in Backup mode.Useful for overcoming ACL restrictions. Make sure to run this with elevated privileges.
/Jcopy using unbuffered I/O (recommended for large files).As said in the explanation, recommended for large files. If you are copying small files, then an unbuffered I/O isn’t worth it.
/EFSRAWcopy all encrypted files in EFS RAW mode.Allows copying encrypted files without having to decrypt the data.
/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).These are the flags to determine what you want to copy. Default is /COPY:DAT.
/SECCopy files with SECurity (equivalent to /COPY:DATS).Useful if you just want to copy over security changes.
/COPYALLCOPY ALL file info (equivalent to /COPY:DATSOU).Easier to type in compared to adding all the flags.
/NOCOPYCOPY NO file info (useful with /PURGE).Copies only the file; no additional data is copied.
/SECFIXFIX file SECurity on all files, even skipped files.Copies security permissions even when the file data hasn’t changed.
/TIMFIXFIX file TIMes on all files, even skipped files.Copies timestamps even when the file data hasn’t changed.
/PURGEdelete dest files/dirs that no longer exist in source.Use this only if you are sure you won’t need to restore a file in the future.
/MIRMIRror a directory tree (equivalent to /E plus /PURGE)./MIR is fantastic at mirroring a directory. Just be sure you won’t need to restore data that has accidentally been deleted from the source.
/MOVMOVe files (delete from source after copying).Same as if you cut & paste a file from one folder to another. Does not delete the source folder.
/MOVEMOVE files AND dirs (delete from source after copying).The Microsoft provided explanation is misleading. /MOVE moves files to a destination, then deletes the files and the source folder. By default, this command doesn’t include subdirectories. Must include /S or /E to include subdirectories.
/A+:[RASHCNET]add the given Attributes to copied files.Add Read only, Archive, System, Hidden, Compressed, Not content indexed, Encrypted, Temporary, Offline.
/A-:[RASHCNET]Remove the given Attributes from copied files.Remove Read only, Archive, System, Hidden, Compressed, Not content indexed, Encrypted, Temporary, Offline.
/CREATECREATE directory tree and zero-length files only.This mimics the structure of the source, though the files contain no data. Use /E to include subdirectories.
/FATcreate destination files using 8.3 FAT file names only.Truncates file and directory names to meet FAT 8.3 standards of 8 characters only.
/256turn off very long path (> 256 characters) support.By default, Robocopy supports paths longer than 256 characters; only use this switch if you want to disable that support.
/MON:nMONitor source; run again when more than n changes seen.Continually monitors the source every minute for saved changes. Once n changes have been met, the copy runs. CTRL + C to escape the monitor.
/MOT:mMOnitor source; run again in m minutes Time, if changed.Continually monitors the source every m minutes. Once a change is detected, the copy runs. Can run in combination with /MON:n
/RH:hhmm-hhmmRun Hours - times when new copies may be started.Robocopy only runs the copy during the times specified.
/PFcheck run hours on a Per File (not per pass) basis.Checks the scheduled /RH (run hours) per file instead of per pass.
/IPG:nInter-Packet Gap (ms), to free bandwidth on slow lines.Instructs Robocopy to pause n milliseconds between transferring blocks of data.
/SLcopy symbolic links versus the target.Copies the symlink versus the actual file the symlink points to.
/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.By default, Robocopy uses 8 CPU threads when copying files. You can use the /MT parameter to specify the use of more CPU threads.
/DCOPY:copyflag[s]what to COPY for directories (default is /DCOPY:DA). (copyflags : D=Data, A=Attributes, T=Timestamps). Specifies what directory data to copy.
/NODCOPYCOPY NO directory info (by default /DCOPY:DA is done).Won’t copy directory info such as attributes, data, and timestamps.
/NOOFFLOADcopy files without using the Windows Copy Offload mechanism.Bypasses Windows offload mechanism. I’m hard-pressed to find a reason to actually use this parameter besides maybe stress testing.

File selection options

Switch ExplanationNotes
/Acopy only files with the Archive attribute set.Ignores files that do not have the archive attribute set.
/Mcopy only files with the Archive attribute and reset it.Copies files that have the archive attribute and then removes the archive attribute from the source file.
/IA:[RASHCNETO]Include only files with any of the given Attributes set.Only copies files that have any of the specified attributes set.
/XA:[RASHCNETO]eXclude files with any of the given Attributes set.Exclude files that have any of the specified attributes set.
/XF file [file]...eXclude Files matching given names/paths/wildcards.Use this parameter to exclude files based on names and paths. Use wildcards to expand the results.
/XD dirs [dirs]...eXclude Directories matching given names/paths.Similar to XF, it excludes any given directories. Remember, directories are not returned by default, so this needs to be used with /S or /E.
/XCeXclude Changed files.Excludes files with the same timestamp but different file sizes.
/XNeXclude Newer files.Excludes files newer than the copy in the destination.
/XOeXclude Older files.Excludes files older than the copy in the destination
/XXeXclude eXtra files and directories.Does not delete extra files located in the destination not found in the source, even when /PURGE and /MIR are used.
/XLeXclude Lonely files and directories.Exclude files located in the source directory but not found in the destination directory. New files are not added to the destination directory.
/ISInclude Same files.Copy files even if there are no differences between the source and destination.
/ITInclude Tweaked files.Include files that are the same size and have the same timestamp but have different attributes.
/MAX:nMAXimum file size - exclude files bigger than n bytes.Exclude files bigger than a given size.
/MIN:nMINimum file size - exclude files smaller than n bytes.Exclude files smaller than a given size.
/MAXAGE:nMAXimum file AGE - exclude files older than n days/date.Exclude files older than a given age.
/MINAGE:nMINimum file AGE - exclude file newer than n days/date.Exclude files newer than a given age.
/MAXLAD:nMAXimum Last Access Date - exclude files used since n.Exclude files not accessed since a given date.
/MINLAD:nMINimum Last Access Date - exclude files used since n. (If n < 1900 then n = n days, else n = YYYYMMDD date).Exclude files with a last access date newer than a given period.
/XJeXclude Junction points and symbolic links. (normally included by default).If you do not need to include junction points and symbolic links, use /XJ which may resolve infinite loops and other issues.
/FFTassume FAT File Times (2-second granularity).Use this to copy system times more reliably, especially when copying between systems such as Windows’ NTFS and Linux’s EXT4.
/DSTcompensate for one-hour DST time differences.Use /DST when Robocopy wants to copy all files because of the DST time difference.
/XJDeXclude Junction points and symbolic links for Directories.If you do not need to include junction points and symbolic links for directories, use /XJD which may resolve infinite loops and other issues.
/XJFeXclude symbolic links for Files.Exclude junction points for files.
/IMInclude Modified files (differing change times).Includes same files with different timestamps. Use in conjunction with /IS and /IT to make sure everything is overwritten.

Retry options

SwitchExplanation Notes
/R:nnumber of Retries on failed copies: default 1 million.Number of times that Robocopy retries a failed copy. Not sure why the default is set to 1 million, which seems excessive.
/W:nWait time between retries: default is 30 seconds.The amount of time Robocopy waits before attempting a retry.
/REGSave /R:n and /W:n in the Registry as default settings.Saves the number of retries and the wait time as the default in the registry.
/TBDWait for sharenames To Be Defined (retry error 67).Waits for a share name to be defined on a “Network Name Not Found” error.
/LFSMOperate in low free space mode, enabling copy pause and resume (see remarks).Helpful when you can’t move or delete files because of insufficient disk space. See remarks for further details.
/LFSM:n[KMG]/LFSM, specifying the floor size in n [K:kilo,M:mega,G:giga] bytes.Helpful when you can’t move or delete files because of insufficient disk space. This switch lets you set the floor size. See remarks for further details.

Logging options

SwitchExplanationNotes
/LList only - don’t copy, timestamp or delete any files.Delete any files. No actual copying is performed. /L shows you what your Robocopy command will do without actually doing it. Good to combine with /LOG to review prior to running.
/Xreport all eXtra files, not just those selected.Reports extra files located in the destination folder that were not part of the copy.
/Vproduce Verbose output, showing skipped files.Provides more detailed information about the robocopy job.
/TSinclude source file Time Stamps in the output.Time stamps are not shown in the output by default.
/FPinclude Full Pathname of files in the output.Outputs the actual full path to each file copied.
/BYTESPrint sizes as bytes.Forces larger files to output their size in bytes instead of displaying larger size increments like MB or GB.
/NSNo Size - don’t log file sizes.Stops displaying file sizes for each file copied.
/NCNo Class - don’t log file classes.Does not return copied item classes such as “New File” and “Newer.”
/NFLNo File List - don’t log file names.Does not output individual files as they are copied.
/NDLNo Directory List - don’t log directory names.Does not output directory names as they are copied.
/NPNo Progress - don’t display percentage copied.Robocopy displays the progress of a file copy in percentage format. /NP disables that progress from being displayed.
/ETAshow Estimated Time of Arrival of copied files.Displays the estimated time of arrival for copied files based on the copy speed of the first file. Must copy more than one file to see the ETA output.
/LOG:fileoutput status to LOG file (overwrite existing log).Creates a log file containing the output of the robocopy job.
/LOG+:fileoutput status to LOG file (append to existing log).Instead of overwriting the preview log, the output is added to an already existing log.
/UNILOG:fileoutput status to LOG file as UNICODE (overwrite existing log).A log file is saved in unicode format.
/UNILOG+:fileoutput status to LOG file as UNICODE (append to existing log).A copy job output is added to an existing unicode log file.
/TEEoutput to console window, as well as the log file.When you use /LOG, the output isn’t returned to the console; it is only displayed in the resultant log file. Use /TEE to create a log file AND display the results in the console.
/NJHNo Job Header.Removes the ROBOCOPY job header, which is displayed by default.
/NJSNo Job Summary.The summary of the job will not be output which is displayed by default.
/UNICODEoutput status as UNICODE.Outputs the status in UNICODE format.

Job options

SwitchExplanation Notes
/JOB:jobnametake parameters from the named JOB file.This switch calls the parameters of an already existing Robocopy job file.
/SAVE:jobnameSAVE parameters to the named job file.Saves the current Robocopy parameters to a Robocopy job file, which can be called again in the future.
/QUITQUIT after processing command line (to view parameters).Doesn’t actually run the Robocopy command. Combine this with the /SAVE option to save a Robocopy job without actually running the Robocopy command.
/NOSDNO Source Directory is specified.Does not specify a source in a job file.
/NODDNO Destination Directory is specified.Does not specify a destination in a job file.
/IFInclude the following Files.Any file names or filters added to the Robocopy command are added to the job file with the /IF switch.

Back in the day, using /PURGE or /MIR on the root directory of the volume caused Robocopy to apply the requested operation on files inside the System Volume Information directory as well. This is no longer the case. If either is specified, Robocopy skips any files or directories with that name in the top-level source and destination directories of the copy operation.

The modified files classification applies only when both source and destination file systems support change timestamps (e.g., NTFS) and the source and destination files have different change times but are otherwise the same. These files are not copied by default; specify /IM to include them.

Using /LFSM requests Robocopy to operate in low free space mode. In that mode, Robocopy pauses whenever a file copy causes the destination volume's free space to go below a 'floor' value, which can be explicitly specified by the LFSM:n[KMG] form of the flag. If /LFSM is specified with no explicit floor value, the floor is set to ten percent of the destination volume's size. Low free space mode is incompatible with /MT, /EFSRAW, /B, and /ZB.

Robocopy examples

Okay, now that my fingers are nice and numb, how about we look at some Robocopy examples? The goal here isn’t to give you an example for every possible scenario. Instead, I want to provide you with a general idea of what the various parameters do and how they work. Understanding the parameters helps you envision how best to use them in your environment.

Default parameters

Let me just knock this one out of the park real quick. Even when you provide the bare minimum with your command, Robocopy still includes several parameters by default. Most of these parameters are listed as default options in the table above.

If you ever want to see what options are set by default, run the following command.

robocopy "source" "destination" /QUIT

This returns the following information.

Screenshot showing default Robocopy parameters, listed in text below.

As you can see, if you don’t specify any additional parameters, the defaults are:

Default ParameterDescription
*.*returns all files.
/DCOPY:DAreturns directory data and attributes.
/COPY:DATreturns data, attributes, and timestamps for files.
/R:1000000retries one million times.
/W:30waits 30 seconds between retries.

This is what you can expect from Robocopy if you don’t specify any other options. I added the /QUIT parameter just to make sure the job didn’t actually run since I only wanted to see what the default parameters were.

Basic copy job

While the default options are okay (albeit a bit excessive with the retry settings), usually when I copy something, my intention is to copy everything, including subdirectories. Let’s look at the Robocopy syntax that accomplishes this.

robocopy "source" "destination" /E /DCOPY:DAT /COPY:DAT /R:5 /W:10
Screenshot of the Command Prompt showing Robocopy syntax that copies everything, explained in text below.

As you can see from the screenshot above, the command copied three files and one directory from C:\Gov_Secrets to C:\Public_Knowledge. Notice that the switch /S was added automatically. This is the expected result. Any time you add /E to a Robocopy command, /S is automatically added. We’ve also instructed Robocopy to retry five times and wait 10 seconds before each retry.

Mirroring and purging

/MIR is simultaneously one of the best and scariest options with Robocopy. If you know what you’re doing, /MIR is great. If you don’t know what you’re doing, you can be left with missing files and no backup.

/MIR syncs two directories. Many users see this as a great backup option, which it can be. However, keep in mind that if a file gets deleted from the source accidentally, it also gets deleted from the destination copy when the Robocopy command runs. If you think you will ever need to restore a file that may have accidentally been deleted from the source, then I would not recommend using /MIR or /PURGE.

On the flip side, /MIR and /PURGE are great at keeping your backup tidy as you clean up your source directory. If you don’t use /MIR or /PURGE, then your destination copy may balloon in size since it will never delete any files, even if you delete them from the source directory.

robocopy "source" "destination" /MIR /DCOPY:T /COPY:DAT /R:3 /W:5
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.

I’ve got a couple of interesting things to point out after running this command. Notice that the switch /PURGE was automatically added even though it wasn’t in the original command. Also notice that an extra file called “How The Universe Actually Started.txt” appeared in the destination folder. Because we ran the /MIR parameter, which automatically adds the /PURGE switch, this file was removed from the destination folder.

Remember, /MIR can be your friend, but it can also be your unreliable friend who betrays you when you least expect it. Or perhaps exactly when you expect it.

Moving multiple files and directories

If you just need to move multiple files and directories from one location to another, you can use the /MOV or /MOVE parameters. This is similar to cutting and pasting data from one directory to another.

I prefer copying files from one location to another rather than manually deleting the source data just in case the move job encounters an error, but to each their own. If you like to live dangerously, then /MOV and /MOVE may be the adrenaline fix you’re looking for. Consider adding the /ZB switch to help resolve any issues encountered during the move job.

robocopy "source" "destination" /MOVE /E /COPYALL /DCOPY:DAT /ZB /R:4 /W:7
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.

Let’s break this down because this command is interesting. The description provided with the /MOVE command is a bit deceiving. /MOVE moves the files inside the source folder to a new folder and then delete the source folder. It won’t touch subdirectories.

Imagine this. You have Folder1 and Folder2. Folder1 only has files in it, no subdirectories. /MOVE moves all the files from Folder1 into Folder2, then deletes Folder1.

Now, if you have subdirectories in Folder1, you need to include /E in order to move both files and subdirectories. This is probably what most people are trying to do with this command. The /COPYALL and /DCOPY:DAT is just to ensure everything comes over unless you don’t want to bring over permissions and such. I’ve included /ZB just in case it’s a large transfer that may get interrupted and in case permissions cause a file transfer issue. And finally, I’ve included the /R and /W parameters. I like to add these with all of my Robocopy commands to ensure something doesn’t hang forever.

Monitoring backups

/MON and /MOT allow Robocopy to continually run on a system, monitoring for file changes. This allows Robocopy to serve as a kind of pseudo backup service. /MON:n checks for a specified number of changes before making another copy pass. /MOT:n waits for a specified period of time before performing another copy pass. These switches can be combined, so both conditions must be met before Robocopy completes another pass.

robocopy "source" "destination" /E /MON:5 /MOT:10
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.

As you can see in this screenshot, Robocopy still runs as it waits for the conditions to be met. /MON:5 instructs Robocopy to wait for five changes to be detected before running another pass. /MOT:10 instructs Robocopy not to make another pass for at least 10 minutes. With this combination of /MON:5 and /MOT:10, Robocopy does not run for at least 10 minutes. After 10 minutes, if five changes have been made, then a copy pass runs. If, after 10 minutes, five changes haven’t been made, Robocopy continues to wait for those five changes before running. To end the process, simply use the CMD abort command, which is CTRL+C.

Filtering files and folders

One of the more powerful features of Robocopy may also seem like one of the simpler ones: the ability to exclude or filter files and folders. Robocopy gives you a ton of options to make sure you copy exactly what you want and only what you want.

From the “File Selection Options” section in the parameters table, there are 24 different parameters to filter with. Not 42, but 24. Let that sink in. That’s a lot of options, which is the whole point. Robocopy was designed to ensure users could have complete control over their copy jobs. This one’s for you, fellow control freaks.

Before we dive into the actual switches, it’s important to note that you can filter files without actually adding any switches. Here’s a basic example:

robocopy "source" "destination" filename
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.
Screenshot showing that the copied file remains in the source.
Screenshot showing that the specified file has been copied to the destination.

Notice that since I included the actual file name that I wanted to copy (“My Name Is Inigo Montoya.txt”) only that one file was copied, even though there are other files in the source folder.

You can extend this functionality even further by using wildcard symbols. Wildcards are symbols that take the place of unspecified characters. There are two well-known wildcards, and there are a couple of lesser-known, or “undocumented,” wildcards.

WildcardDescription
* (asterisk)The * wildcard matches any sequence of characters. This is the most popular wildcard symbol given its usefulness.
? (question mark)The ? wildcard matches any single character. While the * wildcard matches any given number of characters, the ? only matches and substitutes a single character.
> (greater than)The > wildcard is similar to the ? wildcard, the only difference is that the > can be placed after a {dot} to prevent the {dot} from matching the end of the name. The > is an undocumented wildcard. It is not widely known or used among users.
< (less than)The < wildcard matches any 0 or more characters in either the base name or the extension, but never both. Unlike the * wildcard, a single < cannot match characters in both the base name and the extension. The < is also an undocument wildcard. It is not widely known or used among users.

Let’s take a look at a few wildcard examples.

robocopy "source" "destination" b*
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.
Screenshot showing how the above code successfully copies files beginning with the letter b from the source to the destination.

With the b* parameter included, you’re telling Robocopy that you only want to copy any files that start with the letter b. In the screenshot above, you can see that “Bare Necessities.txt” and “Bear Grylls.txt” were the only files to get copied over because they both start with the letter b.

You can include the wildcard symbol anywhere in a file name. In fact, when you run the most basic Robocopy command, you can see that by default, the *.* file filter is included, which means all files will be included.

Here’s an example of using the ? wildcard.

robocopy "source" "destination" "file_n?me.txt"
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.

If you need to copy only files that do not have file extensions, you could use the < wildcard. Here is an example:

robocopy "source" "destination" "<"
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.
Screenshot showing that only files without file extensions were copied from the source to the destination.

Notice that only the files without file extensions were copied over. Take note that we used quotation marks surrounding the < wildcard. If you don’t enclose the < wildcard in quotes, you’ll receive an error that says, “The syntax of the command is incorrect.”

You can also extend the functionality of wildcards to include directories by adding the /S or /E switch.

robocopy "source" "destination" a* /S
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.
Screenshot showing how the above code copies directories beginning with the letter A from the specified source to the destination.
Screenshot showing how the above filter applies to both files and folders recursively, only copying only items that begin with the letter A.

What’s important to note is that when you add a file filter and include subdirectories, the filter applies to both files and folders recursively. In other words, the filter also applies to the files contained in the subdirectories that meet the filter criteria. As you can see from the example above, since I filter anything that started with the letter “a”, the folder “Area 51 Alien Communication Files” was copied, but only one of the files inside of that folder was copied.

If you’d rather specify what you want to exclude, use /XF to specify files you wish to exclude and /XD to specify directories you want to exclude.

You can also use the wildcard symbol to filter by file type. *.docx only includes files of the .DOCX type. *.txt only includes files of the .TXT type.

If you want to include more than one filter, simply include a space between each filter.

robocopy "source" "destination" a* b* *.txt *.docx *.jpg

This example copies .TXT, .DOCX, and .JPG files that start with the letter a and b.

If you want to filter based on attributes, you can use the /IA:[RASHCNETO] to include certain attributes or /XA:[RASHCNETO] to exclude specific attributes. The switch options are as follows:

Switch optionDescription                                                        
/RRead only
/AArchive
/SSystem
/HHidden
/CCompressed
/NNot content indexed
/EEncrypted
/TTemporary
/OOffline

/MAXAGE, /MINAGE, /MAXLAD, /MINLAD are all useful for filtering based on the age or the access date of the file. /MINAGE is especially useful for filtering out files that haven’t been touched in years.

robocopy "source" "destination" /MINAGE:365

This command copies only files that have been modified within the last year. As you can imagine, this is great when you have those users or departments that struggle to clean up their older files.

With so many filter options, it’s difficult to cover them all, but there is one more that I would like to highlight, and that’s the /XO switch. This switch excludes files that have newer versions in the destination directory. This is useful if you have users working out of both the source and destination folders. You don’t want to accidentally overwrite a file that a user has been working on in the destination folder, and this switch stops that from happening.

Screenshot of the Command Prompt showing how the /XO switch excludes files that have newer versions in the destination directory.

Network transfers

Transferring files across the network can be stressful for any sysadmin, depending on the situation. You may need to migrate your files to a new file server, or maybe you need to capture a backup of some network files. Regardless, there are a few Robocopy switches that can help you ensure a smooth transfer process.

ParameterDescription
/ZBAs I mentioned earlier, this parameter helps overcome unexpected issues, especially when you are transferring files across an unreliable network. It also helps mitigate permission restrictions.
/COPYALLIf you are copying files to a new file server, you’ll want to make sure you copy all file settings, especially ACL permissions, so users are still able to access their files on the new server.
/RHTo ensure you don’t bog down the network during work hours, use the run hours switch. You can specify exactly when Robocopy is allowed to run. This is also useful to make sure you aren’t copying files that users are currently modifying.
/MTThe multi-threaded parameter helps speed up your file transfers by increasing the number of CPU threads used to transfer files.

Note that when transferring network files, users have reported issues when targeting mapped drives, so it’s recommended that you use full UNC paths in your Robocopy commands.

robocopy "source UNC path" "destination UNC path" /COPYALL /E /ZB /RH:1900-0500 /MT:64 /R:10 /W:10 /V /TEE /LOG:"C:\Logs\Robocopy_Log.txt"

These are some pretty standard options you’ll want to consider when doing a big network transfer job. We're using full UNC paths for our source and our destination. The /RH:1900-0500 option specifies that we only want Robocopy to run from 7 p.m. to 5 a.m. Once 5 a.m. hits, the Robocopy job pauses, which should prevent Robocopy from bogging down the network during work hours. We’ve included some logging options as well with /V, /TEE, and /LOG, which we will cover more in-depth in a moment.

I want to emphasize that no two network environments are the same. You'll need to evaluate your network to determine which switches and options you need to complete your file transfers. I strongly suggest you use /PURGE and /MIR cautiously when transferring critical network files, or really any vital data. Robocopy is terrific at deleting files if you're careless with your commands.

Logging

By default, Robocopy outputs quite a bit of information to the console window. I find this pretty sufficient for most small Robocopy jobs. However, when you're dealing with critical files or transfers of hundreds of GB or even TB of data, it’s good practice to have an actual log file to review, especially if an issue occurs.

Much like its options for everything else, Robocopy offers an abundance of logging options. While most options are user-preference settings to either minimize or maximize what data is logged, there are a few standouts.

ParameterDescription
/LOGThis one is pretty straightforward as it simply saves the log information to a log file rather than just outputting it to the console window.
/LOG+Use this option if you want to append log information to an already existing log file. Be aware that if you transfer large numbers of files, especially on a scheduled task, this can make your log file balloon into a file that is several gigabytes in size.
/TEEThis sends the log information to a log file as well as the console window.
/FPThis switch provides the full path address to the file, making it easier to find files that may have encountered an issue during the copy job.
/VThis enables verbose logging, which returns more detailed information about the Robocopy job. Specifically, it includes information about skipped files, not just files that were actually transferred.
Screenshot showing a log without a verbose switch.
Screenshot showing a log with a verbose switch.

You can see the difference between these two logs, one with the verbose switch, and one without it.

Here is an example of a command that generates a verbose log file with the date included in the file name. I use the /TEE switch to also send the output to the console window.

robocopy "source" "destination" /TEE /FP /V /LOG:"C:\Logs\Robocopy_V_Log_%date:~-10,2%"-"%date:~7,2%"-"%date:~-4,4%.txt

Robocopy jobs

Robocopy allows you to save and call upon job files. This could be very helpful if you find yourself running the same long list of Robocopy commands over and over again. Robocopy commands can grow exceedingly long, especially if you have to include a lot of filter options.

Here’s how to save and call upon job files via Robocopy:

  • /SAVE:job_name → Saving a Robocopy job is as simple as adding the /SAVE command to the end of your Robocopy command. Make sure it is the last switch added to the command, as any other options added after the /SAVE switch will not be saved. The file will be saved with a .RCJ extension.

  • /JOB:job_name → Calling a Robocopy job file is just as simple as saving it. Simply enter the /JOB switch with the name of the job file you want to run.

Here is a simple example to create a Robocopy job file.

robocopy "source" "destination" /COPYALL /SAVE:"C:\Robocopy Job Files\job1" /MIR

As you can see, I’ve purposefully included the /MIR option after the /SAVE option. If I view my job file, /MIR is not there.

Screenshot of the job file showing how including /MIR after /SAVE saves the Robocopy job without the /MIR component.

Now, if I add the /MIR parameter before the /SAVE parameter, my copy options look like this.

Screenshot of the job file showing how including /MIR before /SAVE saves the Robocopy job with the /MIR component.

To run a job, execute Robocopy with the /JOB:file_name option. When the job file runs, you’ll see all of the parameters passed by it.

robocopy /JOB:"C:\Robocopy Job Files\job1.RCJ"
Screenshot of the Command Prompt showing what happens when you run the above code.

If you want to edit a job file, but you don’t want to run a command to do it, you can modify job files with any text editor. By default, the job files are filled with comments, though they can be trimmed down to the bare minimum parameters if that’s more your style.

Here’s a job file I edited to contain the bare minimum information.

Screenshot of a job file edited to contain the bare minimum.

And here is the result from running the job file.

Screenshot of the Command Prompt showing what happens when you run a bare minimum script, explained in the following text.

As you can see, without the comments, the job file is much smaller, and all that’s really needed is the source, destination, and switches.

Two other options I’d like to briefly discuss related to Robocopy jobs are the /NOSD and /NODD parameters. These options let you leave the source and destination locations out of your job files. When you run the job file, you need to include the information. This is useful if you need to run the same job in multiple locations.

  • /NOSD → No source specified. This will automatically be added to the job file when you leave the source directory out of the command.

  • /NODD → No destination specified. This will automatically be added to the job file when you leave the destination directory out of the command.

robocopy *.txt /SAVE:"C:\Robocopy Job Files\job2"

When you call this job, you want to include the source and destination information. The job contains the options you previously saved, but you can append more options that aren’t in the job file if you wish.

robocopy /JOB:"C:\job_file_location\job_name.rcj" "C:\source" "C:\destination" /COPYALL

You can see in this example that I’ve called the job file, though I’ve also included the /COPYALL switch, which wasn’t included in the job file.

Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.

The filter m* from the job file remained intact, and the /COPYALL option was also included.

Testing Robocopy commands

Since we like to play it safe with utilities that can easily wipe out an entire file server, it’s a good habit to test our Robocopy commands before running them on production data. We want to do whatever we can to prevent an oh no, not again type of situation.

Running your commands against test files and folders is a great way to ensure your command is doing what you want it to do. However, there is one other testing method that you should probably start using before you go full contact IT on your network, and that’s the /L switch.

  • /L → Provides details about the command you are running, with all of the files and folders that would be affected, without actually running the command.

You can use the /L switch to give you a preview of what will happen when you actually run your command. I like to also send the results to a log file for review.

robocopy "source" "destination" /E /COPYALL /L /TEE /LOG:log_file
Screenshot of the Command Prompt showing what happens when you run the above code, explained in the following text.

As you can see, the job looks like it runs and returns all of the results, but if I view the destination folder, it will be empty, just like in my dreams.

Screenshot showing an empty destination folder.

Another easy way to tell if the job didn’t actually run is you won’t have the percentages next to the file indicating the copy status.

Now let’s remove the /L switch and compare the actual results.

Screenshot of the Command Prompt showing what happens when you run the above code without the /L switch, explained in the following text.

As you can see, with the /L switch removed, the copy status of the files is displayed.

Robocopy return codes

Here is a list of the Robocopy return codes and their meanings. Exit codes 0–7 are success codes, and anything >= 8 indicates a failure.

Exit CodeMeaning
0 No errors occurred, and no copying was done. The source and destination directory trees are completely synchronized.
1One or more files were copied successfully (that is, new files have arrived).
2 Some extra files or directories were detected. No files were copied. Examine the output log for details.
3(2+1) Some files were copied. Additional files were present. No failure was encountered.
4Some mismatched files or directories were detected. Examine the output log. Housekeeping might be required.
5 (4+1) Some files were copied. Some files were mismatched. No failure was encountered.
6(4+2) Additional files and mismatched files exist. No files were copied and no failures were encountered. This means that the files already exist in the destination directory.
7(4+1+2) Files were copied, a file mismatch was present, and additional files were present.
8Some files or directories could not be copied (copy errors occurred and the retry limit was exceeded). Check these errors further.
16Serious error. Robocopy did not copy any files. Either a usage error or an error due to insufficient access privileges on the source or destination directories.

Running Robocopy with PDQ Deploy

Need to run a Robocopy job against multiple machines? PDQ Deploy will have you transferring files all over the place in no time. PDQ Deploy allows you to deploy a command or batch file with just a few clicks. Don’t have PDQ Deploy? Download a free trial so that you can follow along.

  1. With PDQ Deploy open, click New Package.

  2. Give your package a name.

  3. Click New Step > Command.

    Screenshot of the PDQ Deploy interface showing New Step > Command.
  4. Enter the Robocopy command you want to run against targets.

  5. Add the success codes 0,1,2,3,4,5,6,7.

    Screenshot of the PDQ Deploy interface showing entering success codes 0,1,2,3,4,5,6,7.
  6. Click Save, and your package is now ready to deploy to your targets.

The other methods

I've never really given it much thought, but there are a lot of different ways to move a file. Let’s go over a few other common methods of transferring files and see how they stack up to the competition.

Drag and drop

Hover your mouse over a file, click and hold, drag the file to another location such as another open folder or the desktop, then let go of the file.

Screenshot showing the drag-and-drop method for moving a file.

Just to note, you might expect a Hitchhiker’s Guide-esque result if the file you copy is huge:

“For a moment, nothing happened. Then, after a second or so, nothing continued to happen.”

In other words, this manual approach takes a notoriously long time for large files. Godspeed, friend.

Right-click, copy/cut, and paste

Right-click on a file and select Copy or Cut. Right-click anywhere in the destination folder and select paste. Copy obviously copies the file. Cut removes the file from the current location once it’s been moved to its new destination. This is usually my go-to method when I need stuff moved and don’t really care about the details.

Screenshot showing how to copy a file from its current location.
Screenshot showing how to paste a file to its destination.

Ribbon menu

Select the file you want to copy and select Home from the ribbon menu. Next, select Move to or Copy to. If the destination you want is in the list of locations, select it; otherwise, select Choose location… and browse to the destination folder, then select either Move or Copy. (I’d be interested to see how many people actually use this method. As for me, I’m far too lazy.)

Screenshot showing how to move a file via the ribbon menu.

Command Prompt

If you’re old school or aspire to be a hacker one day, then you’ve obviously been using Command Prompt to transfer files. The commands you want to use are the move or copy command. Here’s the syntax.

move "source_file" "destination"

or 

copy "source_file" "destination"

Example:

move "C:\Users\brock.bingham\Music\Movin’ On Up.mp3" "C:\Users\brock.bingham\To The East Side"

PowerShell

PowerShell is the option of choice for those sysadmins who try to accomplish everything, and I do mean everything, with PowerShell. Need to rename a shortcut on a desktop? PowerShell. Need to reboot? PowerShell. But how does it compare to Robocopy? Well, I know a few PowerShell fanatics, and even they usually stick with Robocopy, though they may launch it from the PowerShell console instead of the Command Prompt. I think it’s because they prefer the color blue.

Here’s the syntax:

Move-Item -Path "C:\Folder 1\file.txt" -Destination "C:\Folder 2\"

or

Copy-Item -Path "C:\Folder 1\file.txt" -Destination "C:\Folder 2\"

Example:

Copy-Item  -Path "C:\Users\brock.bingham\Documents\Super Secret Files\Unannounced Marvel Movies Roadmap.txt" -Destination "C:\Users\brock.bingham\Documents\Not So Secret Files"

PowerShell power user?

Check out The PowerShell Podcast: a weekly exploration of tips and tricks to help you step up your PowerShell game.

Xcopy

Xcopy (extended copy) has been around for a long time. We’re talking DOS 3.2 long. Xcopy was developed to provide more functionality than just the “copy” command. Xcopy is still available to use with Windows 11, Windows 10, and Windows Server 2019, though it has been deprecated in favor of Robocopy.

Here's the syntax.

XCopy "source_file" "destination"

Example:

XCopy "C:\Users\brock.bingham\Documents\Super Secret Files\How The Universe Was Actually Created.txt" "C:\Users\brock.bingham\Documents\Not So Secret Files"

There are many more parameters that can be used with Xcopy; this is just the basic usage.

File copy step in PDQ Deploy

PDQ Deploy allows you to build custom packages that you can then deploy to hundreds or even thousands of targets. One option when creating a package in PDQ Deploy is the File Copy step. With the File Copy step, you simply select a source and a target folder. It’s about as simple as it gets. Okay, maybe it’s not quite as simple as the drag and drop method, but when you need to do it for hundreds of computers, this option is one of the best.

  1. Launch PDQ Deploy.

  2. Click New Package.

  3. Name your package.

  4. Click New Step > File Copy.

  5. Select your source folder.

  6. Select your target folder.

  7. Click Save.

Your new package is ready to be deployed to all of your adoring fans … I mean users.


It’s really quite impressive how many options one tool can have for a task as simple as copying files. However, once you dive into the intricacies of file copying, you begin to realize why Robocopy has such a massive number of options. When it comes to protecting data, you need to account for every what-if scenario you may encounter along the way.

Hopefully, this blog has cleared up some of Microsoft's vague parameter explanations and you’ve gained a better understanding of how to implement these options into your Robocopy commands. Honestly, the best way to understand how most of these options work is to simply test them out. I can’t tell you how much time I spent testing the various switches to see what they did. Now, if you’ll excuse me, I need to go ice the nubs where my fingers used to be.

Brock Bingham candid headshot
Brock Bingham

Born in the '80s and raised by his NES, Brock quickly fell in love with everything tech. With over 15 years of IT experience, Brock now enjoys the life of luxury as a renowned tech blogger and receiver of many Dundie Awards. In his free time, Brock enjoys adventuring with his wife, kids, and dogs, while dreaming of retirement.

Related articles