Monday, September 28, 2009

RoboCopy

So you have a huge number of files that you want to copy from one place and put them somewhere else. Perhaps you have updated some of the files and want to make sure the changes are copied but you don't remember which files were changed.

The easiest way to do this would be to drag and drop the folders to merge them but if you have done this before you probably know that this is likely to take long enough that you wonder if there might be a better way.

Fortunately for those using Windows Server 2008, Vista or Windows 7 there is. Robocopy to the rescue! For Windows XP and Server 2003 you can get it via a download from Microsoft.

For this purpose robocopy has some advantages over it's predecessors copy and xcopy and it's alternate bitsadmin in that it copies folders, it has the ability to check to see if a file needs to be copied before copying and it is relatively easy to use.

In my example I will take clipart stored on c:\ and copy it to z:\ I want to log the results and I don't want to copy the thumbnail database so here is my command line.

Set Source=c:\Images\Clipart
Set Dest=z:\Images\Clipart
Set LogFile=ClipartCopyLog.txt
Set SkipFile=Thumbs.db

robocopy "%Source%" "%Dest%" /E /LOG:%LogFile% /TEE /V /FP /XF %SkipFile%

The /E switch tells robocopy to copy empty folders. /LOG is the switch which tells where to write a log to. /TEE logs the results both the the log and displays in the console window. /V presents verbose output which is good for debugging but not needed to run. /FP is also for logging instructing to use full path names. /XF is what allows Thumbs .db to be skipped in the file copy. For more information type robocopy /? in an open command window.

The biggest advantage by far is that if the file already exists and is up to date then it won't try to copy the file which speeds things up quite a bit when merging folders.

No comments: