Get the Network Administrators tool pack

Subscribe to our newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them.

Click Here to get your free tools

Recent Posts



Copy files – only if they have changed.

Post image for Copy files – only if they have changed.

by Steve Wiseman on November 25, 2010 · 2 comments

in BAT Files,Tips,Tools,Windows


I got a note from Thomas:

Like everyone else I’m always tweaking the network and I really appreciate newsletters…What I’m looking for is a good batch file the looks for changes to file folders on one drive and only updates those changes during a copy files to another drive.

This is an excellent question. There is a free Microsoft utility that will do this for you. It is called Robocopy. Robocopy is part of the Windows 2003 resource kit. Better yet, it is now included with Windows Vista, Windows 7, and Windows 2008.

If you don’t have one of those newer versions of Windows…get the resource kit from here:

Windows 2003 Resource Kit

Download and install it, and you will find robocopy.exe in the installation folder. It is a stand-alone application. You can copy robocopy.exe around to any machine and it will work.

So now back to the original question. How to copy files to a another drive, or server – only if they have changed?

Using robocopy, we can call it with this set of options to copy everything from “c:\source” to “\\server1\c\dest” including sub-directories:

robocopy c:\source \\server1\c\dest /e /r:0 /w:0

Robocopy will look at the date and time stamp of each file. If the file has not changed, it will skip it.

Lets look at some of those command line options I used:

/e - This tells it to include sub-folders, even if they are empty

/r:0 - Retry on failure zero times. No retries in my example, but this option is great on those unreliable and slow wan links. You can set the retry high so it will keep restarting the copy on failure

/w:0 - The number of seconds to wait between failures

The one thing the above command won’t do is delete files on the destination if they have been deleted on the source. You can do this with the /purge option:

robocopy c:\source \\server1\c\dest /e /r:0 /w:0 /purge

Use this option with care! Take note that it will delete files on the destination. If you supply an empty directory for the source, you will end up with an empty directory on the destination.

There are a huge number of options available in robocopy, and you can see them by just typing robocopy /? at the command line.

This is a great little utility, best of all it is free. I highly recommend checking it out, and I am sure you can find a use for it.

One more thing…Subscribe to my newsletter and get 11 free network administrator tools, plus a 30 page user guide so you can get the most out of them. Click Here to get your free tools

Related Articles:

{ 2 comments… read them below or add one }

1 nathan November 29, 2010 at 2:46 pm

Hi Steve – enjoy your posts. Robocopy is a great tool, but I often struggle with getting the switches right.

I use SyncToy alot. Doesn’t have the power of Robocopy but it works in alot of situations, and can be run from task scheduler.

2 Alan December 20, 2010 at 12:33 am

You don’t need robocopy to do said copy. Just use xcopy [source] [destination] /d. Not picking a date after /d will specifically tell xcopy to check the date/time of the file(s) being copied. (If you choose to pick a date; however, xcopy will only copy the files after said date. Personally, I just use /d by itself. According to Computer Hope, xcopy has been in use since DOS version 3.3.

Leave a Comment

Category Links - Windows Forum - Exchange Forum