Skip to main content
PDQ.com mobilePDQ.com desktop
Support
Try Now

Hitchhiker's Guide to Robocopy

Brock BinghamBrock Bingham
·

Moving files from one location to another is one of the most basic tasks a user can perform on a computer.  It’s probably slightly more complex than turning your computer on and off (unless you’re trying to turn on an iMac and didn’t realize the power button is located on the back, which is definitely not a real-world example by yours truly).  However, while copying a few files here or there can be a simple undertaking, transferring vastly, hugely, mind-bogglingly large amounts of files across a network can get very complex, very quickly.  But, don’t panic.  This guide is here to help you out.  We’re taking a deep dive into Robocopy and finding out what makes it the utility of choice when it comes to file transfers.

Table of Contents

The “Other” Methods

I had never really given it much thought, but there are a lot of different ways to move a file.  Let’s go over a few of the more common methods of transferring files and see how they stack up to the competition. If you'd like to skip all of this, you may do so by clicking here.

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.

Right-click Copy/Cut & Paste:

Right-click on a file and select Copy or Cut.  Right-click anywhere in the destination folder and select paste.  Copy will obviously copy the file.  Cut will remove 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.

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.)

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"

Congratulations, you have successfully passed the hackers 101 course!

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"

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 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.

What Is Robocopy?

Now that we’ve gone over a few of the alternative methods for transferring files, let’s take an in-depth look at Robocopy and find out why it’s my go to method for transferring all of my Vogon poetry files.

Robocopy, which stands for robust file copy (not robot copy, unfortunately), is a command-line utility for copying/replicating/moving files and directories.  It was developed to be more robust (hence the name) than 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

Options, options, options.  Robocopy has more options than you can shake a stick at.  If you’re the type of person that buys a fully-loaded car simply because it came 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 will probably never use most of the options, but it’s comforting to know that they’re there.

Robocopy Options

Let’s take a moment to really break down all the options.  Options in robocopy, sometimes called parameters, arguments, or switches, add to, modify, or extend a command’s functionality.  If you ever want to view what additional options can be set for a given command, simply enter the command followed by /?.  For example, to return all of the available options for robocopy, run this in the command prompt.

robocopy /?

As you’ll see, this command will return a long list of available parameters, letting you copy files where, when, and how you want.  To make this information a little easier to digest, I’ve gone ahead and listed all of the available parameters in this handy-dandy table.  I’ve also included my own notes on each parameter 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. Will automatically add /S into the command.
/LEV:n only copy the top n LEVels of the source directory tree./LEV:1 will copy only files from the root source folder. /LEV 2 will copy the files in the root source as well as the first level of subdirectories and so on.
/Zcopy files in restartable mode Will allow 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.
/SECFIX FIX file SECurity on all files, even skipped files.Will copy security permissions even when the file data hasn’t changed.
/TIMFIXFIX file TIMes on all files, even skipped files.Will copy 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. Will not delete the source folder.
/MOVEMOVE files AND dirs (delete from source after copying).The Microsoft provided explanation is misleading. /MOVE will move files to a destination, then delete 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 will mimic the structure of the source, though the files will contain no data. Use /E to include subdirectories.
/FAT create destination files using 8.3 FAT file names only.Will truncate file and directory names to meet FAT 8.3 standards of 8 characters only.
/256 turn 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.Will continually monitor the source every minute for saved changes. Once n changes have been met, the copy will run. CTRL + C to escape the monitor.
/MOT:mMOnitor source; run again in m minutes Time, if changed.Will continually monitor the source every m minutes. Once a change is detected, the copy will run. Can run in combination with /MON:n
/RH:hhmm-hhmmRun Hours - times when new copies may be started.Robocopy will only run the copy during the times specified.
/PF check 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 Will copy 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.Will ignore 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 will exclude any given directories. Remember, directories are not returned by default, so this will need to be used with /S or /E.
/XCeXclude Changed files.Excludes files with the same timestamp but different file sizes.
/XN eXclude 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.Will 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 will not be 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:n MINimum 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 will retry 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 will wait 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
/L List only - don’t copy, timestamp or delete any files. delete any files. No actually 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.Will report 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.
/TS include 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.
/BYTES Print sizes as bytes.Will force 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.
/NC No 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.Will not output individual files as they are copied.
/NDLNo Directory List - don’t log directory names.Will 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 will disable that progress from being displayed.
/ETAshow Estimated Time of Arrival of copied files.Will display 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 will be added to an already existing log.
/UNILOG:fileoutput status to LOG file as UNICODE (overwrite existing log).A log file will be saved in unicode format.
/UNILOG+:fileoutput status to LOG file as UNICODE (append to existing log).A copy job output will be 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 currently 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.Will not specify a source in a job file.
/NODDNO Destination Directory is specified.Will not specify a destination in a job file.
/IFInclude the following Files.Any file names or filters added to the robocopy command will be added to the job file with the /IF switch.

Remarks

Using /PURGE or /MIR on the root directory of the volume formerly 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 will skip any files or directories with that name in the top-level source and destination directories of the copy session.

The modified files classification applies only when both source and destination filesystems 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 will pause whenever a file copy would cause 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.

Examples

Okay, now that my fingers are nice and numb, how about we look at some 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 will help 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 will return the following information.

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.  The /QUIT parameter was added 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 even if a bit excessive with the retry settings, usually when I’m copying something, my intention is to copy everything, including subdirectories.  Let’s look at a more practical example that will accomplish this.

robocopy "source" "destination" /E /DCOPY:DAT /COPY:DAT /R:5 /W:10

As you can see from the screenshot above, the command copied 3 files and 1 directory from C:\Gov_Secrets to C:\Public_Knowledge.  Notice that the switch /S was added automatically.  This is the expected result.  Anytime you add /E to a robocopy command, /S will automatically be added.  We’ve also instructed robocopy to retry 5 times and wait 10 seconds before each retry.

Mirror And Purge Examples

/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 sync’s 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 will also be deleted in the destination copy when the robocopy command runs next.  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 cleaned up 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 they are deleted in the source directory.

robocopy "source" "destination" /MIR /DCOPY:T /COPY:DAT /R:3 /W:5

A couple of interesting things to point out after running this command.  You’ll notice that the switch /PURGE was automatically added even though it wasn’t in the original command.  You’ll also notice that an extra file called “How The Universe Actually Started.txt” was located 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 crazy friend that betrays you when you least expect it.  Or perhaps exactly when you expect it.

Moving Files And Directories

If you just need to move 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

Okay, time to break this down.  This command actually proved more interesting than I thought it would.  The description provided with the /MOVE command is a bit deceiving.  /MOVE will move the files inside the source folder to a new folder and then delete the source folder.  It will not touch subdirectories.

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

Now, if you have subdirectories in Folder1, you will 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.  Last but not least, 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.

Using /MON and /MOT To Monitor Backups

/MON and /MOT will 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 will complete another pass.

robocopy "source" "destination" /E /MON:5 /MOT:10

As you can see in this screenshot, robocopy is still running as it waits for the conditions to be met.  /MON:5 instructs robocopy to wait for 5 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 will not run for at least 10 minutes.  After 10 minutes, if 5 changes have been made, then a copy pass will run.  If, after 10 minutes, 5 changes haven’t been made, robocopy will continue to wait for those 5 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. 

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

You’ll 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 ? will only match and substitute 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*

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.  

The wildcard symbol can be included at any point of 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"

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

robocopy "source" "destination" "<"

You’ll 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 which 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

What’s important to note is that when you add a file filter and include subdirectories, the filter will be applied to both files and folders recursively.  Meaning, the filter will also apply 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 will only include files of the .docx type.  *.txt will only include 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 will copy .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 will only copy 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 will exclude 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 will stop that from happening.

Network Transfers

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

ParameterDescription
/ZBAs I mentioned earlier, this parameter will help overcome unexpected issues, especially when you are transferring files across an unreliable network. It will also help 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 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 will help speed up your file transfers by increasing the number of CPU threads used to transfer files.

Note - When transferring network files, users have reported issues when targeting mapped drives, so it’s recommended to 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 are 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 PM to 5 AM.  Once 5 AM hits, the robocopy job will pause, 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 will need to evaluate your network to determine which switches and options you’ll 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 are careless with your commands.

Logging

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

Staying consistent with the theme of this blog, 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 amounts of files, especially on a scheduled task, this can make your log file balloon into a file that is several gigabytes in size.
/TEEThis will send the log information to a log file as well as the console window.
/FPThis switch will provide 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 will return more detailed information about the robocopy job. Specifically, it will include information about skipped files, not just files that were actually transferred.

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 which will generate 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

I feel like this may be one of the lesser known features of robocopy.  Maybe it’s just something that I haven’t used very often that other sysadmins use all the time.  Either way, if you are the “Robocopy Guy” at your organization and you eat a bowl of robocopy crunch for breakfast every morning, this would probably be very helpful.  Then again, if you are the robocopy guy, you probably already know about 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.

/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, there /MIR will not be there.

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

To run a job is as simple as executing robocopy with the /JOB:file_name option.  You’ll see all of the parameters passed by the job file when it runs.

robocopy /JOB:"C:\Robocopy Job Files\job1.RCJ"

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.

And here is the result from running the job file.

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 go over that relate 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 will 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’ll want to include the source and destination information.  The job will contain 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.

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 start testing 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 - Will provide details about the command you are running, with all of the files and folders that would have been 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

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

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.

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

Robocopy Exit Codes

Here is a list of the robocopy return codes and what they mean.  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 commands and batch files  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

  4. Enter the robocopy command you want to run against targets.

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

  6. Click Save, and your package is now ready to deploy to your targets.

Wrapping Up

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 amount 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 gain 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.

Ready to get started with PDQ Deploy & Inventory? Work less, automate more.

Start your 14-day free trial
Sign up in seconds

Don't miss the next post!

8 ways to protect your business from ransomware

Ransomware attacks are on the rise, and it's only a matter of time before your business becomes a target. Learn how to protect yourself before it's too late.

General
PDQ.com
© 2021 PDQ.com Corporation
Products
  • PDQ Deploy ®
  • PDQ Inventory ®
  • SimpleMDM
  • Pricing
  • Downloads
  • Licensing
  • Buy