Beginners Guides: Understanding and Creating Batch Files
Batch files can save time by automating specific actions
taken on the computer down to one simple click. They can also potentially
hide damaging code, so a good understanding of what they are,
how they work, and how to create your own, is crucial to today's IT
force. - Version 1.2.0
In this Beginners Guide, PCSTATS is going to walk you through one of the simplest but
potentially most powerful ways to customize and simplify the management of your
computer: batch files. These text files are easy to create, and only as complex
as you want them to be, but they can perform many useful operations from file
backups to system configuration quickly and automatically.
At their simplest, batch files are text files which execute one or more command prompt commands in a specific order.
The power of a batch file lies in the way that it allows you to
combine multiple commands into one batch file 'program' and customize the way
that each command operates.
In this article PCSTATS will illustrate what batch files are good for and how to
create them. By creating a useful series of batch files designed to allow
you to selectively back up files from one location to another, we'll demonstrate
the ways that batch files can make your computing life easier while you
learn the various option involved in creating them.
What can batch files do for
you?
If you read PCSTATS Guide to the Windows XP Command Prompt,
you'll have a passing familiarity with several very useful command
prompt commands. Batch files can incorporate any command prompt command
(including the switches for that command), execute multiple commands in sequence
and choose which commands to use based on user input or the results of previous
commands. Essentially, anything you can do in the command prompt you can
do better and faster with batch files once you have prepared them.
This article deals exclusively with using the Microsoft Windows XP/2K command
prompt to create batch files, so commands here may not be 100% compatible with
earlier versions of Windows which used a true DOS prompt (and the same holds
true in reverse; true DOS batch files may not work under Windows XP). The
range of commands available to produce batch files actually decreased with the
Windows XP/2K command prompt implementation, but the essential functions are
still present.
How are batch files created?
As we've said, batch files are simply text files, so all you need to create one
is the Windows notepad application. Don't use WordPad or a word processor
like Microsoft Word; these do not produce 'pure' text files by default,
since they add their own text formatting.
To create a simple batch file, all you need is a single command you want to
run, typed into a text file and saved with the .BAT extension, like
'mybatchfile.bat'. Double click this file and it will run your command.
Let's test it out...