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:
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