home *** CD-ROM | disk | FTP | other *** search
- I. HARD DISK ORGANIZATION
- AND SOME NEAT THINGS TO DO WITH BATCH FILES
-
-
-
- This article assumes some familiarity with subdirectories and
- paths. Subdirectory names are given in uppercase, to distinguish
- them from file names. "Cd" is the DOS command to change directory.
-
-
- OVERALL ORGANIZATION:
-
- Large applications which contain many program files, such as
- databases, word processors, spreadsheets, etc. should each be in
- their own "first-level" subdirectory (ie. at root level). The data
- files they use may be in "second-level" subdirectories under the
- application subdirectory, or in "first-level" subdirectories. I
- prefer the former.
-
- A good hard disk organization should look something like this
- hypothetical one, with the subdirectories on the left being at root
- level and the ones indented under them at second level:
-
- \BASIC
- \BAT
- \DBASE
- \DBASE\INVENTORY
- \DBASE\VIDEO
- \DBASE\BOOKS
- \DOS
- \LOTUS
- \LOTUS\FINANCE
- \LOTUS\MISC
- \WORD
- \WORD\LETTERS
- \WORD\MISC
- Ibmbio.com (invisible)
- Ibmdos.com (invisible)
- ansi.sys
- autoexec.bat
- command.com
- config.sys
-
- I don't use many BASIC programs, so I keep them all in the same
- subdirectory as the language program, since there is only one
- language file in gwbasic (and two in IBM BASIC, I believe).
-
- In addition to the subdirectories, the root should contain only
- a few necessary files, basically the ones shown above, and possibly
- others that some applications may require there. For convenience,
- and to prove I am not a fanatic, I throw a few miscellaneous files in
- the root: rdclk.com and stclk.com (for my battery-operated clock-
- calendar), and sit.com (for parking my hard disk). Ansi.sys and
- vdisk.sys (if a ram disk is to be used) can be placed in the
- subdirectory \DOS if config.sys contains the lines:
- device = c:\DOS\ansi.sys
- device = c:\DOS\vdisk.sys
-
-
- THE AUTOEXEC.BAT FILE:
-
- A special file which must be named autoexec.bat can be put in
- the root, and will do certain things each time the hard disk is
- booted, such as set the time and date if a clock-calendar is
- installed, and set a path. The file should be something like this:
- break = on
- prompt = $p $q$g
- path = c:\; c:\DOS; c:\BAT
- cls
- rdclk
-
- I like to use the prompt line given, to modify the DOS prompt to
- display the path to the current subdirectory ($p), an equal sign
- ($q), and the normal "greater-than" sign ($g), so it looks like this:
- C:\ =>
- C:\BASIC =>
- C:\WORD\MISC =>
-
-
- THE PATH STATEMENT:
-
- The DOS subdirectory is included in the path so DOS commands can
- be issued from any subdirectory. Putting the BAT subdirectory in the
- path allows a neat bit of trickery, detailed below. The path may need
- to be augmented with other subdirectories for certain special
- applications, but there is no reason to put all of them there.
-
-
- THE BATCH FILE SUBDIRECTORY:
-
- Let's say you want to start Lotus. If its subdirectory is not
- in the path, you would normally have to type "cd\lotus" then "lotus".
- But there is a better way. If applications are accessed by batch
- files which are all in a subdirectory in the path, you can start any
- application from any subdirectory. The BAT subdirectory takes the
- place of putting all the subdirectories in the path.
-
- I like to give each batch file the name of the command to start
- the application (but the extension is .bat). Each one contains, at
- least, commands to do the appropriate cd and start the application:
- lotus.bat:
- cd \LOTUS
- lotus
-
- When you type a command at the DOS prompt, the computer will
- look for a .com or .exe file of that name, or (failing that) .bat, in
- the logged subdirectory, and if it doesn't find it there, in the
- subdirectories in the path. (One caution -- if you are already in
- the application subdirectory, and the batch file has the same name as
- the application's starting command, the batch file won't be found --
- the .com or .exe file in the current subdirectory will.)
-
- This \BAT system is a sort of "transparent" menu system. With
- this organization, any application can be started from any
- subdirectory (at any level) merely by typing its name (the name of
- the appropriate batch file) at the DOS prompt.
-
- You can also put other useful commands in these batch files.
- For instance, in some applications you may wish to include commands
- to set the printer to other than its usual configuration and reset it
- after the application has run, to turn a screensaver off for an
- application then back on again, etc. After the application quits
- control will return to the batch file and pick up any commands after
- the call to the application. I also include in \BAT several files
- which are stand-alone printer commands, to let me easily set some
- feature of my printer when I am not in an application that lets me do
- it, such as indenting the left margin before I "type" a file to the
- printer from DOS. For more information on printer commands, see the
- accompanying article "Printer Commands From Batch Files".
-
- A menu of these "application batch files" can even be made (as
- another batch file), and started on each boot by putting its name as
- the last item in the autoexec.bat file. It can loop so that whenever
- an application finishes, the menu is displayed again. If this is
- done, one of its options should be to exit to DOS.
-
-
- A SPECIAL TRICK FOR RUNNING BASIC PROGRAMS:
-
- You can write a batch file to run a BASIC program so you don't
- have to enter and exit BASIC manually. To start gwbasic and run a
- BASIC program named filename.bas (assuming both are in the \BASIC
- subdirectory):
- filename.bat:
- \BASIC\gwbasic \BASIC\filename
- (You real IBM users substitute basica.) The BASIC program should end
- with "SYSTEM", to dump you right back to DOS where you were. By
- including the path(s), no matter what subdirectory you called it
- from, the computer can find both gwbasic and the program to run.
-
-
- II. WRITING BATCH FILES
-
-
-
- A batch file is just a "list" of DOS commands, executed in the
- order given. It is an ASCII text file with the extension .bat. Some
- of the DOS commands are useful only in batch files, and constitute
- what is essentially a simple programming language built into DOS.
- You run a batch file by typing its name, without the extension, from
- the DOS prompt.
-
- You can write batch files in three ways: from the DOS prompt
- using the "copy con filename.ext" command ("copy from the console"),
- in EDLIN, or using a text editor. EDLIN is a line-oriented editor
- built into DOS. It is primitive by the standards of full-screen
- editors, and therefore not intuitive to use, but don't be daunted by
- it -- you don't have to be an assembly jock to use it. And it's
- always there at the DOS prompt.
-
- To use "copy con", from the DOS prompt:
- Type: copy con filename.bat
- (use the name with which you want it saved)
- The cursor drops to the next line
- Type the line(s) desired
- When each line is done hit Enter
- On the last line type Ctrl-Z and Enter
- This ends and saves your file, and you are now a DOS "power-user".
-
- To write a batch file using EDLIN, from the DOS prompt:
- Type: edlin filename.ext
- (use the name with which you want it saved)
- You will get an * prompt
- Type: I (for insert)
- You will get a 1:*
- Type the line(s) desired
- When the line is done hit Enter
- You will get a 2:*
- Type: Ctrl-Z and Enter
- You get the * prompt again
- Type: E (to save the file and exit to DOS)
-
- To write a batch file from a text editor, do it as you would any
- other document, but if you are using a full-fledged word processor,
- be sure to save the file unformatted (ie. as an "ASCII file").
-
-
- SPECIAL BATCH FILES WITH NON-KEYBOARD CHARACTERS:
-
- Some batch files, especially those which contain printer
- commands, may contain non-keyboard ASCII characters. These
- characters have to be entered in a special way. For all of the
- characters except ESC, it is done in all three of the above methods
- (although not all text editors have this feature) by holding down the
- Alt key while you type the character's ASCII code number (one to
- three digits) on the numeric keypad. (These are the numbers given in
- the CHR$()'s in the BASIC version of a command.) When you release
- Alt a funny symbol will appear at the cursor, a different one for
- each code. The symbols for some codes are the regular alphanumeric
- and punctuation characters you can type on the keyboard (ASCII codes
- 32-127), and for these you can just type the character. If there is
- any doubt whether you have the right character, do the Alt-number to
- be safe. Either way gives the same result in the file. Don't hit a
- spacebar between different codes, don't use the numbers above the
- main keyboard, and you don't need Num Lock on.
-
- There is no way to enter the escape character using "copy con",
- although you can enter a "dummy" character, then go into DEBUG or a
- similar utility and substitute the hex code for ESC for that of the
- dummy character. The ESC character can be entered in EDLIN by a
- control-V followed by a left square bracket. As far as I know, all
- of the text editors which allow the alt-number technique allow ESC to
- be entered just like any other character, as alt-27.
-
- For the printer control batch files discussed in the article
- "Sending Printer Commands From DOS", it is sometimes desirable to
- avoid carriage return and line feed characters at the end of the
- file. You can do this in "copy con" by hitting Ctrl-Z at the end of
- the line, not on a new line. But this won't avoid a LF in an "echo"
- file; it is useful only in a "codes-only" file used by a "type"
- command, and you can't easily do most of those from "copy con", since
- it is not easy to put in the ESC character. As far as I know, you
- can't avoid them in EDLIN, but you can delete them from the file with
- at least some text editors, or DEBUG or one of the utilities that
- lets you look at and modify a file in hex. The CR is 0D and the LF
- is 0A in hex. (These are two of the characters given in an ASCII
- table.) You can avoid them in a text editor if you leave the cursor
- on the line right after the last character.
-