Robocopy Command Prompt Folder Copying and Backup Guide

OK, so you want to copy or move a bunch of files – probably from one drive to another, and Windows File Copy is a pain. Or you want your own custom backup onto an external drive. Robocopy is a utility that was part of the Windows Resource Kit, but since Vista it has been incorporated into Windows (7, 8 and 10). This is a keep it simple guide to how to use robocopy.

First of all, Robo is short for Robust, not robotic. Yeah, they cheated a little with the name, but it’s designed to be able to tollerate faults and errors and get what can be copied copied, without pausing for a user to decide if they want to overwrite, and so on. So, it’s robust. But it can also be very dangerous. If you have say a thumb drive with one file on it, you tell it to mirror that drive onto your main hard drive, and robocopy will happily wipe your entire C Drive. So be warned! Double check before running.

The beauty with robocopy is you can run it, get half way through, then just stop it and start again whenever you like. It is also very easy to automate by putting it in a Windows Batch File (instructions below), so you can run it every day as a backup.

What Does Robocopy Look Like?

If you open a command prompt (Win+R then type cmd and press enter), you can see all of the 50,000 options for robocopy by typing:

robocopy /?

and press enter. But how do you just use it?

The format is: robocopy source target switches

Robocopy Example – Backup

OK, simple example. Let’s say you want a backup of C:\Users\Fred (source) and you want to put it on your external hard drive E: in the same named folder, so E:\Users\Fred (target)

Here’s the command:

robocopy C:\Users\Fred E:\Users\Fred /MIR /Z /XO /W:0 /R:0 /NP

There are many possible switches. The order is unimportant. This is what the the above switches mean:

/MIR Mirror. This copies from one directory to another, and OVERWRITES EVERYTHING in the target directory. It also copies and overwrites ALL SUBDIRECTORIES. Very powerful. Rather dangerous. If you are using this for a backup, it will delete any files (and folders) that are in your backup that are not in your source. So if you specified a empty source, or accidentally targeted the whole drive, you are going to lose a lot of data.

/Z Copy files in restartable mode. This is a very good idea.

/XO eXcluding Older. It doesn’t overwrite newer files with older versions. It will still delete files if you use MIR

/W:0 /R:0 This is Wait 0 seconds, and Retry 0 times. This is what I ususally use for local files, or maybe /W:1 /R:1. Over a network you can increase these to retry many times.

/NP No Progress. Otherwise it shows percentage copied. It’s just cleaner without this, especially if you output to a file.

You can either run this in the command prompt, or you can create a batch file to make it quicker next time (one click).

Creating a Batch File

To create a batch file, just right click in a folder, select new, and select text file.

Rename it something like MyBackup.

Now, you may or may not see the file extenion (.txt) with the file name.

In this case MyBackup.txt. If you don’t see the .txt, then you need to click on View (tab at the top), then tick File name extensions (as I have below):

Then you can rename the file to a batch file (.bat) by just right clicking on the file and rename. You should get this error message:

If you don’t get that error message, they you aren’t changing the file name. You are probably creating a text file called MyBackup.bat.txt. This won’t work. Make sure you change the extension (by ensuring you can see File name extensions), and it should then have a different icon (a gear) and the type should change to Windows Batch File (see below):

OK, you have a real batch file. To edit it, right click on the file and choose edit (left clicking will run it, and we don’t want to do that yet).

This will open Notepad.

Tip: If you want to save the output (result) of the robocopy to a log file, add the /LOG option as follows (to the correct directory for you, obviously:

Then save this file, and then left double click to run it. Once it is finished, you will have a comprehensive log file saved wherever you told it to. If instead you want to output to your screen, I suggest adding a pause so the screen doesn’t close when the robocopy finishes:

Folder Names With Spaces

If you are trying to copy from or to a folder with spaces in the name, surround the entire path with quotes:

robocopy “C:\Users\Fred\My Documents” E:\Users\Backup /MIR /Z /XO /W:0 /R:0 /NP

robocopy “C:\Users\Fred\My Documents” “E:\Users\Fred Backup” /MIR /Z /XO /W:0 /R:0 /NP

Copy With No Deleting

Just use /E intead of /MIR to copy all subdirectories without deleting files on the target it they don’t exist on the source. Eg:

robocopy C:\Users\Fred E:\Users\Fred /E /Z /XO /W:0 /R:0 /NP

This will leave any extra files and folders on the target. This is useful for adding files to an existing repository, or if you are just a bit terrified of /MIR

There are dozens more options, but those are the main ones. Enjoy!

Leave a comment