Now we are going to create a useful batch file that will copy all the files
in your 'c:\testsource' directory into your 'c:\testbackup' directory each time
you run it. We'll also make it so that the next time you run that batch
file, it will only copy the files that have changed and new files, not every
single one in the 'c:\testsource' directory. Ideally you'd use this batch
file to copy your files onto a second hard drive or removable media like a USB
key, but we'll leave it as it is for now. Feel free to change the target
directory to something more useful later.
First we need to create a couple of dummy files in our c:\testsource
directory to give us something to work with:
Navigate to your c:\testsource directory in Explorer and right click on the
empty space inside. Select 'new\text document.' Call your new text
file 'testdoc1'. Now right click again and create a new bitmap
image. Call your image 'testbit1'. Your c:\testsource directory
should now have the following contents:
Creating your second batch file
Now to create a batch file to backup these files into your c:\testbackup directory automatically. Open up notepad and type
c:\testsource c:\testbackup /m /e /y
The '@echo off' line tells the computer not to
display anything onscreen when it runs this batch file.
The second line uses the xcopy command to copy all contents of the
c:\testsource' directory to c:\testbackup the first time the batch file is
run. The second time and all remaining times, it will only copy new files
and files which have changed since it was last run. It will not copy
unchanged files which it previously copied, even if you delete the copies it
made from the c:\testbackup' directory.
Now save your batch file as 'testbackup.bat' on your desktop and double click
it to run the script.
Check the contents of your c:\testbackup directory. It
should now have copies of the two files you created in c:\testsource. Good stuff. Now open 'testdoc1'
in your c:\testsource directory and add some text then save it.
Run your testbackup.bat batch file again, and go to the 'testdoc1' file in
the c:\testbackup folder. It should have been updated with the changes you
made in the other folder.
You've now created a useful backup utility with a simple two-line batch file
that just takes a double click to run. Starting to see the potential
usefulness of knowing your batch files yet?