Using Robocopy to Mirror Directories

Written by Barry Dysert (last updated October 9, 2017)

3

Robocopy is the tool to use when working with entire directories, since that's what it was designed to do. Let's say you want to "mirror" directories, i.e., make two directory trees contain identical files/folders. This is similar to using the /E switch (which is covered under the tip titled "Using Robocopy to Copy Entire Directories") along with the /PURGE switch. (The /PURGE switch tells Robocopy to delete destination files/folders that no longer exist in source.) The shorthand switch to mirror directories is /MIR, so the command to mirror directories is:

C:\> ROBOCOPY C:\Temp1 C:\Temp3 /MIR

This results in the creation of C:\Temp3, and all of the files and folders under C:\Temp1 will be copied to the newly built tree under C:\Temp3. In addition, if C:\Temp3 already existed, any files in its tree that are not in the C:\Temp1 tree will be deleted from the C:\Temp3 tree.

 This tip (13197) applies to Windows 7, 8, and 10.

Author Bio

Barry Dysert

Barry has been a computer professional for over 35 years, working in different positions such as technical team leader, project manager, and software developer. He is currently a software engineer with an emphasis on developing custom applications under Microsoft Windows. When not working with Windows or writing Tips, Barry is an amateur writer. His first non-fiction book is titled "A Chronological Commentary of Revelation." ...

MORE FROM BARRY

Using Two Monitors with Windows

Windows is great about letting you work on multiple things at the same time. Often, however, you end up with so many ...

Discover More

Changing Font Size in a Command Prompt Window

If you work at the command level very much, you may want to change the fonts that are used. You can control what ...

Discover More

Running a Program as Administrator

Sometimes a program you're trying to run needs to run with elevated privileges. Assuming you have the authority to do ...

Discover More
More WindowsTips

Working with Compressed Files and Folders via Zip

Windows 10 provides multiple ways to work with compressed files and folders. One great way is to use the Zip utility, ...

Discover More

Checking a Disk Drive for Free Space

Keeping track of your resources can help you avoid serious computer problems. Having an adequate amount of disk space is ...

Discover More

Permanently Deleting a File

If you have a file that you're sure you want to permanently delete (instead of having it go to the Recycle Bin) it's an ...

Discover More
Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 7?

2018-03-02 23:45:56

george renee

Just to share one thing I read on a Microsoft TechNet:
Although useful in some scenarios, using /Z switch makes copying much slower.
"Copying files in restartable mode is about 6x slower over a network than in normal or backup mode due to the necessary management overhead."
..I use GS RichCopy Enterprise which has features like copying long file path names, copying NTFS file permissions and is not too costly..


2018-02-12 13:08:43

vikas

use robocopy


2017-10-10 11:55:22

Len Richard

I didn't understand exactly what mir did. I copied around 300 cds to an external drive, then delete them from the folder they were in, so I could store more there for backup. When I again backed up this folder to my external drive it wiped out everything i had previously backed up. I did a googlie on this and discovered I was not the only person who got screwed. There needs to be a clear Warning Visible that nobody can miss explaining this. I tried 10 free recover tools, none worked. I finally found a trial version of a recover software, it worked and it cost be 70 bucks to purchase it. It was either that or lose everything. Nice to notice you have this explained. Too bad every other person offering advice doesn't.


Newest Tips