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

Creating a Library

Creating a library can be done with just a couple of clicks. Although it appears that libraries have some issues, you can ...

Discover More

Moving the Videos Library

The Videos folder is one of several system libraries created in Windows by default. This library is specifically ...

Discover More

What is the Purpose of the System Event Log?

The System event log holds messages generated by device drivers. This tip explains more about it.

Discover More
More WindowsTips

Sorting a Folder

When you have a lot of files in a folder, it is helpful to be able to know how to sort through all the files. Windows 10 ...

Discover More

Displaying Details about a Graphics File

Graphics files have additional attributes that other files don't have. This tip describes how you can display these ...

Discover More

Copying Files or Folders

A common operation within Windows is to copy files and folders from one location to another. Here are the two major ways ...

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 six minus 4?

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