|
XCOPY – The forgotten
DOS Command
Since the advent of the GUI –
Graphical User Interface – DOS commands have pretty much been
forgotten, and rightly so. Why type in or create DOS batch files
when someone else has put all these cryptic commands together for
you into a nice graphical program where all you have to do is click
the “Backup” button. Well, there are two reasons: cost and control.
Most graphical programs execute the same DOS command that you could
type in at the command line yourself and perform the same exact
function. You can also control the various aspects of the copy
command via DOS command switches. I’ll explain that in a minute.
It’s all a matter of convenience. The GUI makes us lazy, but we have
to pay for that laziness. Someone else does all the work and you
just click a button. And I don’t have a problem with that if that’s
what you decide you want to do. My goal here is just to let you know
that you do have a choice. With minimal work you can create your own
DOS equivalent
of those fancy GUI programs and save
money. Plus give yourself a feeling of accomplishment.
Let’s start with the DOS command
XCOPY, because everyone wants a
backup of their data. We are going to create a DOS command that
backs up a folder and its subfolders to a destination of your
choosing for safe keeping.
First, let’s get a DOS command box up on the screen.
Start – Run – Cmd

This is our DOS command box where we
can issue commands that emulate the expensive programs. The command
we will be using is xcopy. Now xcopy provides various control
switches that dictate just how the program will perform. Whether it
will copy only new files, or all files. Things like that. So if you
type in: xcopy /? At the command line you see all the
various switches available to us.

As you can see there are a lot. But
that’s good because that helps us control exactly how the command
will act during its copy operation.
The format of the command will be:
XCOPY
[source] [destination] [/switches]
We can use as many switches in the
command as we need.
Here’s a sample command we can use to
analyze and also as a quick reference for the future, just in case
you find yourself wanting to make a quick backup.
xcopy
C:\Source_Folder
E:\Destination_Folder
/D /E /C /R /H /I /K /Y
copy
contents of
C:\source
folder
and subdirectories to
E:\destination
folder and recreate
subdirectories
/D
Switch = Copies files changed on or
after a specified date. If no date is given, copies only those files
whose source time
is newer than the destination time.
/E Switch = Copies directories and
sub-directories., including empty ones.
/C Switch = Continues copying even if
errors occurs.
/R Switch = Over writes read only
files.
/H Switch = Copies system and hidden
files as well.
/I Switch = If destination does not
exist and copying more than one file, assume that destination must
be a directory.
/K Switch = Copies attributes. Normal
xcopy will reset read-only attributes.
/Y Switch = Suppress prompting to
confirm you want to overwrite destination files.
This command will copy all the files,
including those in sub-folders, that are newer in the source folder
when compared to the destination folder. Try it with some
non-critical folders first to verify that you have the process down.
Once you’ve tried this command and
you are satisfied it works. You would then create a batch file (
text file with an extension of .bat ) and copy that command into the
file and schedule it to run daily via the Windows scheduler. That’s
it! You just saved yourself $40.00 on a backup program.
Now keep in mind that you can also
create additional batch files to automatically cleanup the temp
files, defrag your drives, and even reboot your PC. There are
endless possibilities with the command line. You could save your
batch files to a USB memory stick and take them with you to your
friend's house or your PC at work. All free.
Resources:
technet
|