Batch File For Backing Up Files

Whenever I have to completely wipe my C: drive clean, I normally want to back up all my data on it so I can quickly restore settings for various programs. This means copying the Documents and Settings folder, which often includes locked files. This presents a problem because the normal way of copying files via Windows Explorer is interrupted whenever a file that cannot be copied is encountered. And when you’re copying tens of thousands of files at one time, you don’t want to have the process get cancelled half an hour in.

While backing up my laptop hard drive — thanks to what is probably some mysterious driver incompatibility which causes the laptop to boot up to a blank screen — I decided to look around for a solution to this problem. I wanted something that would either copy locked files, or just ignore them , since any file that is locked is likely not one I need to bother backing up anyway.

Luckily, I happened upon an Indonesian blog that contained a DOS Batch file that did much of what I needed except ignore any errors. I copied the batch file and modified it to ignore any errors during the copying process. Here, in all its glory, is my new supercopy.bat file:

@echo off

@rem * Cancel if the user fails to specify a source and destination

if "%1" == "" goto error1
if "%2" == "" goto error2

@rem * Copy from source to destination including subdirs and hidden
@rem * files, continuing on to the next file if an error occurs

echo Please wait...
xcopy "%1" "%2" /E /H /C /I /Q /K
goto endofprogram

:error0
echo Syntax:
echo %0 source destination
goto endofprogram

:error1
echo You must provide a source
goto error0

:error2
echo You must provide a destination

:endofprogram
echo Finished.

With this, the chore of backing up an entire hard drive is a whole lot easier. Here’s an example of how to use it; this will copy the entire contents of the C: drive int a folder called C_BACKUP on the D: drive:

supercopy C: D:\C_BACKUP

I hope this is useful to someone.