Home > Computers & Technology > Software > Software & Web Development
Created on: January 12, 2009 Last Updated: January 15, 2009
If you were using computers back in the days of MS-DOS, then you probably remember how tedious it was to type a series of commands at the DOS prompt to do something as simple as create a directory in a specific folder or delete a block of files. The batch file anticipated that users would sometimes perform functions requiring multiple sequential DOS commands often enough that they would want to be able to easily compile those commands into a simple, intuitive script.
Well, you can't get more intuitive than a batch file. Requiring nothing more than a plain text editor (Notepad, anyone?), creating a batch file is as simple as listing your DOS commands one after the other in plain text and then saving the file with a .BAT extension rather than the default .TXT extension.
The best way to grasp the potential of batch files is to actually create one. Copy and paste the following into Notepad, save it with a .BAT extension, and then try running it.
ipconfig /all pause
If you run this batch file, what you'll get is a screen displaying technical information for your current network connections. "Ipconfig /all" is the command for viewing your network configuration information, and we've added "pause" to prevent the window from closing prematurely before we've been able to have a look at the information we've requested.
Both commands are DOS commands in this case, but they could also just as easily be utilities or programs that we'd like to run. For example:
cd %SystemRoot% notepad.exe
Run this batch file and it will open up Notepad for you. In this case, the first command changes the directory to the variable "%SystemRoot%", which is a stand-in for whatever directory you installed Windows into. The second command executes "notepad.exe", the Notepad program built-in to Windows.
It's that simple. You can see that if you have some extremely complicated work to do at the command line that bears automation, batch files are invaluable.
As a final example, let me show you a batch file I created to help me keep the Windows Desktop free of clutter on some public kiosk computers I manage.
cd c:\Documents and Settings\%username%\Desktop del *.* /q
The first line moves us into the Desktop directory of the user currently logging on to the machine. The Desktop directory happens to be where all the shortcuts, folder and files that the user has created on his desktop are stored. The second line then deletes everything in that directory, so anything that was created there disappears from the desktop. The "*.*" is understood by DOS as a wildcard for everything in the directory, and the "/q" prevents the "del" command, which deletes objects, from prompting the user for confirmation.
On my Windows server I have attached this batch file to my users' accounts as a logon script, so that everytime a user logs on this batch file cleans off their desktop.
Batch files are a quick, intuitive way to automate DOS command functions that need to to be run often. They've saved me lots of headaches and time, and with a little practice they're sure to do the same for you!
Learn more about this author, Jason Garland.
Click here to send this author comments or questions.
Below are the top articles rated and ranked by Helium members on:
Batch file: What it does
By definition a batch file executes a series of commands in written inside an executable plain text file. Special file extensions,
Computers technology doesn't have to be a strange and foreign language that only the elite techno-geeks are able to decipher.
by Allen Teal
When a computer needs to run a preset list of commands a batch file is used. A batch file is actually a very simple form
What does a batch file do? Nothing at all, unless our computer is instructed to execute it.
Batch files, which have the
If you were using computers back in the days of MS-DOS, then you probably remember how tedious it was to type a series of
View All Articles on: Batch file: What it does
Helium Debate
Cast your vote!
Which is a better Web application framework: Ruby on Rails or PHP?
Click for your side.