How to Use Robocopy to Sync Files on a Drive or Directory in Windows


Key Takeaways

  • The Windows robocopy command is a powerful tool for automating file copy and synchronization tasks.
  • Robocopy is particularly useful for backing up files, mirroring drives and directories, and scheduling file copies.
  • Before using robocopy, be cautious as it doesn’t ask for confirmation and can potentially delete or overwrite files. Always double-check command line commands before running them!



Being able to keep files in two locations synchronized is useful for backing up, sharing files, and staying organized. The Windows robocopy command lets you perform file copy and synchronization from the command line, so that these tasks can be automated and scheduled.


What Is the Windows Robocopy Command

The robocopy (robust file and folder copy) is a command line tool available in Windows that copies files from one place to another. It can copy between directories on the same drive, or between devices like USB sticks and portable disks, and to network locations.

When to Use the Robocopy Command

The robocopy command is perfect for automating your workflows. If you regularly have to copy files between the same locations, you can set up a script to do it all for you rather than having to perform the task manually.


It’s particularly useful for performing backup tasks, with the added advantage that you won’t have to remember to perform the backup, improving the reliability of your backup practices. You can use robocopy to regularly back up your files to an external drive, or to cloud storage.

How to Use the Robocopy Command

Right-click the start button, then select 'Terminal' on Windows 11 or 'PowerShell' on Windows 10

To use the robocopy command you need to open the Windows command prompt or Powershell. You can do this by right-clicking on the start menu and selecting either of the Windows Terminal or Powershell options.

The robocopy command doesn’t have a graphical interface, so you call the command with the source and destination directories, files to copy, and a list of the options you want to use to tell it how to behave.

robocopy SOURCEDESTINATIONFILESOPTIONS> 

If no files are specified, all files are copied from the source directory to the destination directory. Commonly used options when using robocopy include:


  • /MIR mirrors the directories, deleting files in the destination that aren’t in the source
  • /MOVE moves files and directories, deleting them from the source once copied
  • /XO files in the source that are older than the destination aren’t copied
  • /XD Exclude directories matching a given name
  • /b backup mode ignores file permissions that block access to files
  • /l list files only, don’t actually do any copying or moving (useful for seeing what would be copied before you actually commit to running the command)
  • /fp shows the full file paths in the output, again useful for seeing what robocopy is up to as it works, and previewing changes during dry runs


It’s worth pointing out that robocopy doesn’t ask for confirmation before it does something. Once you run it, it will move, delete, or overwrite files without warning, so if you’ve made a mistake in your source or destination paths, the files you want to operate on, or with any of the supplied options, data could be irretrievably lost. So, carefully check your command before you run it, test the command, and, of course, back up your files somewhere safe first!

How to Mirror (Make an Exact Copy) From One Drive or Directory to Another

To demonstrate robocopy in action, this command copies all files from the D:\ drive (the source) to the M:\ drive (the destination) on your computer.

robocopy D:\ M:\ /XO /XD "`$Recycle.Bin" "System Volume Information" 

The /XO command tells robocopy not to copy files in the source that are older than those in the destination. This saves time when running the command again later on to copy only the files that have changed.

The /XD command is used to omit the “$Recycle.Bin” and “System Volume Information directories” from being copied. These are special Windows directories that hold files you’ve deleted (but not yet emptied from the Recycle Bin) and store information about the drive. Neither of these directories contain files that are needed by the user, and they often cause errors if you try to copy them, so it’s generally a good idea to leave them out of any copy operations.


Note the use of a backtick (`) before the dollar symbol in the path to the Recycle Bin directory. This is an escape character that prevents the dollar symbol from being misinterpreted as a variable.

As this command is intended for backup purposes, it doesn’t use the /MIR option to make the mirror as that would remove files in the destination that are not in the source, which would make it impossible to recover them if they were accidentally deleted.

Scripting File Copying in Windows With Robocopy

Scripting robocopy is as easy as copying your robocopy command into a batch or Powershell script.

Scheduling Robocopy to Run Automatically

The Windows task scheduler lets you automatically run programs and commands at a specified date/time, on an interval, or on a schedule. You can create a scheduled task to run your batch or Powershell script, containing your robocopy command.


What About Xcopy and Copy Commands?

Xcopy is another built-in Windows file copy command that (with the copy command for copying single files) has been around for a very long time (since the 1980’s!). While xcopy is still used by a lot of people in their scripts to copy multiple files, it is no longer the best tool for copying files. While robocopy hasn’t replaced xcopy per-se—as xcopy is still available in Windows—robocopy is faster, more reliable, and provides more options than xcopy. It does the same job, and does it better.

Robocopy is a robust tool for copying files, but it may not be the best option for inexperienced users, so before you dive in to rolling your own backup scripts, consider other, more user-friendly options. If your goal is to back up your entire computer, you can create a full system image of your Windows system and all files, so that you can restore everything in the case of disaster.


Backing up is the most important thing you can do to prevent expensive (or regrettable) data loss. Losing important work or your family photo collection irreversibly is not something anyone wants to experience, so you should have a well-thought-out backup strategy. You should make sure that the files you want to keep are properly backed up to two safe locations: a copy on a second device like a portable hard drive or USB stick, and another stored on a reputable online backup service.



Source link

Previous articleDestiny 2’s Bungie reveals “Apollo” and “Behemoth” expansions, new DLC roadmap
Next articleThis Phone Saved the Google Pixel