The Explorer: Save Your Butt With DOS: Pulling It All Together
Here's how you can build your own batch files -- or alter those of others
OK, So How Do You Make A Batch File?
It's easy. Again, a batch file is just a plain text file that lists a series -- a "batch" -- of DOS commands, one after another. When the operating system processes a batch file, it simply executes the command in the order they're listed, starting at the top of the file and working down. (If you need a DOS command primer, see the EasyDOS Internet Guide to DOS.)
Although batch files are indeed just plain-vanilla text files, they're given a special extension (bat) instead of the normal text file extension (txt) so the operating system will know that the bat file contains commands that should be processed, rather than text to be displayed.
The easiest way to get comfortable with batch files is to learn by doing, so let's build a very simple demo file. It won't do anything fancy, but it's a safe and easy way to get started with batch programming.
First, we'll perform a simple DOS task by hand; then we'll use a batch file to automate the task.
Here's the manual task: We'll navigate around the hard drive in DOS, and examine the contents of two
1) Open a "DOS window" by clicking on Start/Programs/MS-DOS Prompt, or by typing "Command" (without the quotes) in the Start/Run line. A plain (probably black and white) window will open on-screen. This isn't true or "pure" DOS because Windows is still running and active, but it's all we need for now, and the examples we'll discuss will work exactly the same if you do boot to pure DOS such as by hitting F8 when your hear the system beep when you first turn on your Win9x machine The blinking underline mark you see in the DOS window is the DOS cursor: It appears at what's called the Command Prompt. Depending on how your system is set up, your Command Prompt probably says something like "C:\" or "C:\WINDOWS" or "C:\WINDOWS\Desktop." These are, of course, the names of directories or folders on your hard drive; the Command Prompt is showing you where you are in your hard drive structure. (In the off chance you have a very basic DOS setup, your prompt may only show "C>" and nothing more. If that's the case, type PROMPT $P$G and hit the Enter key to switch to the more descriptive Prompt.)
2) Now let's change to the topmost directory ("folder," in Windows-speak) on your C: drive. That directory is C:\, and the "change directory" command is "CD" so you simply type CD C:\ and press enter. If you weren't already there, your Prompt should now show "C:\>"
3) The command for showing all the files in a directory is DIR, and you can show the resulting
file list in wide format by add "/W" to the command: Type DIR /W and hit enter, and you'll see a display of all the files in the C:\ directory.
4) Now let's change directory to C:\Windows: Type CD C:\Windows and hit enter. Your prompt now says
5) Now display the files in C:\Windows by typing DIR /W and hitting enter.
OK, now let's do the all the above via a batch file:
Start NotePad. (Remember, batch files are plain-vanilla text files: You don't want fancy formatting commands
embedded in the file, such as what you might get using a full-blown word processor.)
In the blank NotePad page, type the following lines:
(Those are, of course, exactly the same commands you typed manually a moment ago.)
Now save your batch file: Click on File/Save As. Use the "Save In" function to navigate to your C:\WINDOWS\Desktop folder. In the "Save as type" input line, select "All Files (*.*)" then in the "File Name" area, name your batch file -- something obvious like TEST1.BAT. Click on save.
Now look at your Windows desktop: there should be a new icon there named TEST1.BAT (or whatever you named
it) and the icon will sport the image of a gear, showing it's a file the operating system can work on.
Double click the icon and your new batch file will run in a DOS window, carrying out the commands you typed in in rapid succession.
Building A Mobile Business MindsetAmong 688 respondents, 46% have deployed mobile apps, with an additional 24% planning to in the next year. Soon all apps will look like mobile apps – and it's past time for those with no plans to get cracking.
Top IT Trends to Watch in Financial ServicesIT pros at banks, investment houses, insurance companies, and other financial services organizations are focused on a range of issues, from peer-to-peer lending to cybersecurity to performance, agility, and compliance. It all matters.
Join us for a roundup of the top stories on InformationWeek.com for the week of October 9, 2016. We'll be talking with the InformationWeek.com editors and correspondents who brought you the top stories of the week to get the "story behind the story."