home *** CD-ROM | disk | FTP | other *** search
Text File | 1986-12-18 | 61.0 KB | 1,684 lines |
- Mass Deletes
- (PC Magazine Vol 5 No 13 July 1986 User-to-User)
-
- It's easy to mass-erase unwanted files by using the ERASE command
- with ? and * wildcard characters. This works file if the multiple
- files have some common elements to their names or extensions, but to
- erase multiple files without common portions of the names you normally
- have to issue the ERASE command once for each file you want to get rid
- of. To get around this problem, and to make it easier to erase several
- files with one command, use this WIPEOUT.BAT file:
-
- ECHO OFF
- :LOOP
- IF !%1 == ! GOTO ALLDONE
- IF EXIST %1 GOTO OKFILE
- ECHO File %1 not found ....
- GOTO GOON
- :OKFILE
- ERASE %1
- :GOON
- SHIFT
- GOTO LOOP
- :ALLDONE
-
- To use WIPEOUT.BAT, type the files you want to erase after the WIPEOUT,
- with spaces between them. For instance:
-
- WIPEOUT c.doc c.wks d.doc
-
- would remove c.doc, c.wks, and d.doc from your disk with a single
- command. The batch file checks to see whether the files you specified
- are on your disk, tells you if they're not, and erases them if they
- are. It uses SHIFT to juggle the specified filenames into the single
- %1 replaceable parameter, and an IF !%1 == ! test to see if it's
- finished.
-
- -----------------------------------------------------------------
- ECHO OFF
- (PC World July 1986 & November 1986 Star-Dot-Star)
-
- The default setting of ECHO ON for batch file commands can be
- quite annoying. The obvious solution is to include an ECHO OFF command
- at the beginning of every batch file. This has the equally annoying
- effect of displaying the ECHO OFF command whenever the batch file
- executes. The ultimate solution is to patch COMMAND.COM to make ECHO
- OFF the default.
- For DOS 3.1, simply change the appropriate byte from 1 to 0.
- To do so, use a copy of COMMAND.COM and proceed as follows:
-
- A>debug command.com
- -e 1967 00
- -w
- Writing xxxx bytes
- -q
-
- For DOS 2.1, patch COMMAND.COM as follows:
-
- A>debug command.com
- -e 096e 00
- -e 1734 3c 1f
- -e 366e 0d 0a 24
- -e 3672 26 c6 06 6e
- -e 3676 09 00 e9 05 e8
- -w
- Writing 4580 bytes
- -q
-
-
- -----------------------------------------------------------------
- Pause, S'il Vous Plait
- (PC Magazine August 1986 User-to-User)
-
- If you distribute disks with batch files on them to non-English
- speaking users, the message "Strike a key when ready ..." generated by
- the PAUSE command may be meaningless. To remedy this, substitute your
- own message by using ECHO and get rid of the normal English message by
- redirecting PAUSE to NUL. This feature works only in DOS 3.0 or later.
- A French version would look like this:
-
- ECHO OFF
- ECHO Presser une touche pour continuer
- PAUSE >NUL
-
- Redirecting messages to NUL is a useful technique that can also prevent
- general batch file screen clutter. Users have learned to start their
- systems by creating a RAMdisk and copying their most frequently used
- files to it. Even with ECHO OFF, the results is a string of "1 File(s)
- copied" messages. To keep the screen clean, add a ">NUL" to the end of
- each COPY instruction.
-
- -----------------------------------------------------------------
- Putting DOS Variables to Work
- (PC World August 1986 Star-Dot-Star)
-
- Buried within the DOS manual is a discussion of a feature that
- enables you to create variables for use within batch files. This
- powerful feature makes creating sophisticated batch files a cinch.
- The technique works because DOS treats the percent sign (%) as a
- special mark that identifies replaceable parameters. When you place
- percent signs on both sides of a name, DOS looks to an area of memory
- called the environment to find the value that replaces the variable
- name. You can put values in the environment with the SET command.
- Suppose you need to use a command frequently within a batch file.
- You could use the SET command to store that command in the environment
- under a short name (such as Z), and then use the variable %Z% within
- the batch file in lieu of the command itself. SKIPLINE.BAT illustrates
- such a situation.
- Values remain in the environment until you remove them or restart
- the computer. Because of this, DOS variables can be enlisted to pass
- values between batch files. One batch file can set a value in the
- environment; subsequent batch files can test that value using the IF
- subcommand, or they can use the value directly as demonstrated in
- SKIPLINE.BAT.
- Editor's Note: DOS reserves 127 bytes for environment space and
- expands that amount automatically unless you've loaded memory-resident
- software such as GRAPHICS.COM or SideKick. If you run out of
- environment space (which will be indicated by a DOS error message),
- use the technique outlined in "For Environmentalists" in PC World
- April 1986 Star-Dot-Star. (This article is contained in the previous
- tips file, DOSTIPS4.ARC. -drw-)
-
- -----------------------------------------------------------------
- Tax-Free Solution
- (PC World August 1986 Star-Dot-Star)
-
- According to IRS regulations, anyone who uses a computer for both
- personal and business purposes must keep contemporaneous records to
- document deductible expenses. You can buy any of several utility
- programs that monitor PC usage, but you can also accomplish the task
- with the batch file USELOG.BAT.
- USELOG.BAT relies heavily on DOS redirection capabilities. It
- requires that you first create a file called CR.DAT and keep it on
- disk so DATE and TIME commands can be redirected. To create CR.DAT,
- type: COPY CON:CR.DAT <Enter>, press <Enter> again, and then <Ctrl>-Z
- and <Enter>. Be careful when creating USELOG.BAT; the presence and
- placement of many characters are critical. This is especially true
- for the greater-than and less-than symbols; if you omit one where two
- are required, the contents of the master file may be erased each time
- USELOG.BAT is run.
- You can invoke the program in two ways: type USELOG followed by
- up to nine words that describe the purpose of the computer session.
- (Do not use the greater-than or less-than symbols in your description.)
- Or simply type USELOG and await prompting for a description. If you
- opt for the latter method, you must remember to press <Ctrl>-Z followed
- by <Enter> to mark the end of the description.
- When it is run, USELOG.BAT appends the date, time, and session
- information to the master file USELOG.DAT. The program performs with
- acceptable speed on a floppy-based system and executes in a flash when
- run on a hard disk. If you have a RAM disk, you may want to modify
- USELOG.BAT to operate on RAM-based files, then copy the master file
- onto a hard or floppy disk. Once the program is working, you can
- easily document all your computer activity -- including changing tasks
- after starting your PC.
-
- echo off
- cls
- rem Note: Requires file CR.DAT containing 1 blank line
- date<cr.dat>>uselog.dat
- time<cr.dat>>uselog.dat
- cls
- echo Purpose: >>uselog.dat
- if X==%1X goto cont
- echo Updating usage log...
- echo %1 %2 %3 %4 %5 %6 %7 %8 %9 >>uselog.dat
- goto end
- :cont
- echo Describe the purpose of this computer session,
- echo then press Ctrl-Z and then press ENTER:
- copy use log.dat+con uselog.dat/b >nul
- :end
-
- -----------------------------------------------------------------
- Fast IBM Batch File Editor
- (COMPUTE! Magazine September 1986 by Tony Roberts)
-
- The power of the batch file quickly becomes evident to anyone who
- works regularly in DOS. The AUTOEXEC.BAT handles a variety of chores
- each time the system is booted, and any number of other BAT files stand
- by, ready to help with such tasks as initializing applications, sending
- out printer codes, and presenting program menus.
- The problem with batch files is that to be effective and helpful,
- they need to be adjusted as your system grows and your applications
- change. Performing the necessary batch-file maintenance, however, is
- often so cumbersome that it's discouraging. Loading a full-blown word
- processor or even using EDLIN to edit a five- to ten-line batch file
- can be a lot more time and trouble than it's worth.
- EDBAT.COM is a full-screen editor with very limited features.
- Because it is designed for speed, it limits itself to files of fewer
- than 512 bytes -- adequate for most batch files. When called, the
- program clears the screen and displays the file you want to edit.
- Using the cursor keys, you can move to the appropriate place, make the
- necessary changes, and press Alt-S to save the edited file. It is not
- impossible to open a file, edit it, close it, and be back at the DOS
- prompt in as little as 15 seconds.
- The price you pay for this fast operation is that EDBAT has very
- few features. You're essentially limited to the regular character keys
- and the cursor keys. The Insert key does not work, the Delete key does
- not work, nor do the function keys perform any function. The Backspace
- key moves the cursor back a character, but it does not perform a delete.
- For batch file editing, none of these is particularly restrictive.
- You're usually just performing one or two simple operations such as
- adding, deleting, or correcting a line. EDBAT can handle all these
- tasks efficiently.
- EDBAT.COM is created from the EDBAT.BAS listing below. To run
- EDBAT.COM, enter this line at the DOS prompt:
-
- EDBAT filename
-
- EDBAT.COM must be on the disk in the current drive when you enter this
- command. Filename is the name of the file you wish to edit. Full
- drive and subdirectory specifications are allowed when indicating a
- filename. If the file is too long or if EDBAT is unable to open the
- file, the program will print a message and exit. If the file you have
- specified does not exist, EDBAT assumes you are creating a new file.
- The file you are to edit is displayed on the screen below a line
- containing the program title and the name of the current file. If you
- have started a new file, the screen's work area will be blank.
- Use the cursor keys to move around the file, editing as needed.
- Notice that a triangle signals the end of each line. If you decide to
- cut a line short, move to the appropriate spot and press Enter. A
- trianble is inserted and the cursor moves to the beginning of the next
- line. The screen may continue to show characters beyond the end-of-
- line marker, but they will be ignored when the file is saved.
- To delete an entire line, simply move to the first position on
- that line and press Enter. An end-of-line marker appears at that
- spot, indicating that the line will be ignored.
- Inserting a line is slightly more difficult since there is no
- insert function. Move the cursor to the end-of-line marker on the
- line that will precede your new line. Press Ctrl-Y and a down-arrow
- character will replace the end-of-line marker. Add the new line right
- after the down arrow and press Enter as usual. When the file is saved,
- the lines will be adjusted.
- When you're finished editing, press Alt-S to save the file. The
- program's save routine reads the screen and saves what it sees to your
- file. It begins with the first line of the text area and continues
- until it finds a space in the first position of any line. EDBAT
- ignores any characters in a line which follow the first end-of-line
- marker.
- The only other option the program offers is Alt-Q, the Quit
- option, which returns you to DOS without changing the original file.
- In nearly every case, your entire file will fit easily on the screen.
- If part of your file scrolls off the screen, use Alt-Q to quit and
- find another method of editing the file. EDBAT cannot save what it
- cannot see.
- EDBAT does not make a backup copy of your original file. In most
- cases, though, a backup copy of a very short file is superfluous.
-
- EDBAT.COM Command Summary:
-
- Alt-Q Quit
- Alt-S Save
- Ctrl-Y Multistatement delimiter (prints as a down arrow)
- Enter End-of-line (prints as left-pointing triangle)
- Space Space in first position of line signals text end
-
-
- EDBAT.BAS:
-
- 10 CLS
- 20 OPEN "EDBAT.COM" AS 1 LEN=1
- 30 FIELD 1,1 AS A$
- 40 PRINT:PRINT"Writing EDBAT.COM to disk....."
- 50 FOR I=1 TO 8:READ B$:GOSUB 130:NEXT I
- 60 FOR I=1 TO 75:B$="5F":GOSUB 130:NEXT I
- 70 B$="24":GOSUB 130
- 80 FOR I=1 TO 74:B$="0":GOSUB 130:NEXT I
- 90 FOR I=1 TO 648:READ B$:GOSUB 130:NEXT I
- 100 CLOSE
- 110 PRINT:PRINT"EDBAT.COM has been created."
- 120 END
- 130 'Write byte to disk
- 140 LSET A$=CHR$(VAL("&H"+B$))
- 150 PUT #1
- 160 RETURN
- 170 DATA E9,E0,0,45,64,42,61,74,2,0
- 180 DATA 2,50,6C,65,61,73,65,20,73,70,65,63,69,66,79,20
- 190 DATA 66,69,6C,65,6E,61,6D,65,2E,D,A,24,45,72,72,6F
- 200 DATA 72,20,6F,70,65,6E,69,6E,67,20,66,69,6C,65,2E,D
- 210 DATA A,24,46,69,6C,65,20,74,6F,6F,20,6C,6F,6E,67,2E
- 220 DATA D,A,24,FC,BF,54,1,BE,80,0,AC,A2,99,1,FE,E
- 230 DATA 99,1,3C,0,75,9,BA,A1,1,E8,7,2,E8,25,2,AC
- 240 DATA 3C,D,74,3,AA,EB,F8,E8,BA,1,73,E,3D,2,0,74
- 250 DATA 30,BA,BC,1,E8,EC,1,E8,A,2,BA,26,4,8B,1E,9A
- 260 DATA 1,8B,E,9F,1,B4,3F,CD,21,3B,6,9F,1,75,C,E8
- 270 DATA A0,1,BA,D2,1,E8,CB,1,E8,E9,1,A3,96,1,E8,91
- 280 DATA 1,E8,CB,1,BA,3,1,E8,B9,1,C6,6,9E,1,0,C6
- 290 DATA 6,9D,1,14,E8,60,1,BE,55,1,33,C9,8A,E,99,1
- 300 DATA AC,8A,D0,80,FA,61,72,3,80,E2,DF,E8,9C,1,E2,F0
- 310 DATA C6,6,9E,1,2,C6,6,9D,1,0,E8,3A,1,83,3E,96
- 320 DATA 1,0,74,1F,FC,BE,26,4,8B,E,96,1,AC,8A,D0,80
- 330 DATA FA,D,75,7,B2,11,E8,71,1,B2,D,E8,6C,1,E2,EC
- 340 DATA E8,14,1,B4,0,CD,16,3C,0,74,13,3C,D,74,A,3C
- 350 DATA 8,B4,4B,74,1C,3C,19,72,EA,E8,1F,1,EB,E5,80,FC
- 360 DATA 48,75,E,80,3E,9E,1,2,74,D9,FE,E,9E,1,E8,E6
- 370 DATA 0,80,FC,4B,75,E,80,3E,9D,1,0,74,C6,FE,E,9D
- 380 DATA 1,E8,D3,0,80,FC,4D,75,E,80,3E,9D,1,4F,74,B3
- 390 DATA FE,6,9D,1,E8,C0,0,80,FC,50,75,E,80,3E,9E,1
- 400 DATA 18,74,A0,FE,6,9E,1,E8,AD,0,80,FC,10,75,6,E8
- 410 DATA FD,0,E8,F,1,80,FC,1F,75,89,C7,6,96,1,0,0
- 420 DATA BF,26,4,C6,6,9E,1,2,C6,6,9D,1,0,E8,87,0
- 430 DATA C6,6,95,1,0,B4,8,CD,10,3C,20,74,4E,3C,11,75
- 440 DATA 9,FE,6,9E,1,E8,6F,0,EB,DE,80,3E,95,1,50,77
- 450 DATA 18,B4,8,CD,10,3C,11,74,10,3C,19,75,1C,B0,D,AA
- 460 DATA FF,6,96,1,B0,A,EB,11,90,B0,D,B4,A,AB,83,6
- 470 DATA 96,1,2,FE,6,9E,1,EB,AF,AA,FF,6,96,1,FE,6
- 480 DATA 95,1,FE,6,9D,1,E8,2E,0,EB,BF,F8,BA,55,1,B4
- 490 DATA 3C,B9,0,0,CD,21,73,9,BA,BC,1,E8,65,0,E8,83
- 500 DATA 0,8B,D8,8B,E,96,1,BA,26,4,B4,40,CD,21,E8,21
- 510 DATA 0,E8,5B,0,E8,6D,0,8A,36,9E,1,8A,16,9D,1,B4
- 520 DATA 2,CD,10,C3,F8,BA,55,1,B0,2,B4,3D,CD,21,A3,9A
- 530 DATA 1,C3,8B,1E,9A,1,B4,3E,CD,21,C3,8A,D0,80,FA,D
- 540 DATA 74,8,E8,25,0,FE,6,9D,1,C3,B2,11,E8,1B,0,B2
- 550 DATA D,E8,16,0,B2,A,E8,11,0,FE,6,9E,1,C6,6,9D
- 560 DATA 1,0,C3,50,B4,9,CD,21,58,C3,B4,2,CD,21,C3,B4
- 570 DATA F,CD,10,88,3E,9C,1,B4,0,B0,2,CD,10,B4,5,B0
- 580 DATA 0,CD,10,C3,CD,20
-
- -----------------------------------------------------------------
- Best Batch Branch
- (PC Magazine Vol 5 No 8 Apr 29, 1986 User-to-User)
-
- Long batch files containing numerous "if ... goto" conditional
- statements tend to slow down dramatically as processing moves further
- along. DOS searches slowly for each new label from the top of the
- file, yielding a pathetic 5- to 10-second delay, even on an AT, if
- the label occurs near the end of a long batch. There is a way to get
- rid of all the labels and "if errorlevel ... goto" statements, allowing
- a batch file to work at top speed and still contain numerous
- conditional branches.
- Most batches can be controlled with a simple Y(es) or other
- single-key response to each request. The GETKEY technique described
- in an earlier User-to-User sets a different errorlevel for every
- response. Because DOS returns a "true" if errorlevel <= the set
- value, batch files ordinarily require four "if errorlevel" tests to
- obtain "true" on Y or y but "false" on other keys.
- GETYES.COM performs these tests, thereby removing them from the
- batch. It sets errorlevel 255 for Y or y and errorlevel 0 for any
- other key. This lets you directly perform an operation with the
- statement "if errorlevel 255 (perform some DOS function)". GETYES.COM
- is created with GETYES.BAS below.
- You can next "if" conditionals on one line of a batch file for
- further flexibility and control; for example, "if errorlevel 255 if
- exist filename (perform some DOS function)" or "if errorlevel 255 if
- x == %1 (perform some DOS function)". This doesn't seem to be
- documented in the DOS manual.
-
- 100 'GETYES.BAS
- 110 OPEN "GETYES.COM" AS #1 LEN=1
- 120 FIELD #1,1 AS D$
- 130 FOR B=1 TO 18
- 140 READ A$:LSET D$=CHR$(VAL("&H"+A$))
- 150 PUT #1:NEXT:CLOSE
- 160 DATA B4,00,CD,16,3C,59,74,04,3C
- 170 DATA 79,75,02,B0,FF,B4,4C,CD,21
-
- Editor's Note: This technique makes batch branching a pleasure.
- If you want to use N and n rather than Y and y to trigger errorlevel,
- substitute 4E for 59 in line 160 and 6E for 79 in line 170, and change
- the reference from GETYES.COM to GETNO.COM. To test this after
- creating the GETYES.COM program, use this TESTTHIS.BAT file:
-
-
-
- echo off
- :start
- echo Hit y or Y or another key
- getyes
- if errorlevel 255 goto :yes
- goto :no
- :yet
- echo ...you said yes
- goto :continue
- :no
- echo ...you didn't hit y or Y
- :continue
- echo Now, want to quit (y/n)?
- getyes
- if errorlevel 255 goto :exit
- goto :start
- :exit
-
- The nesting abilities allow even more power. To test these,
- revise the fifth line of TESTTHIS.BAT to read:
-
- if errorlevel 255 if Z==%1 goto :yes
-
- Then, if you execute TESTTHIS.BAT again, hitting Y or y at the first
- prompt will not result in a branch as it did earlier. To make both
- of the nested conditions true, instead of executing the batch file by
- typing TESTTHIS, at the DOS prompt type:
-
- TESTTHIS Z
-
- and hit Y or y when asked. The Z after the filename will replace the
- %1 parameter, and since both conditions (the errorlevel and the Z==Z)
- are true, the batch file will work as advertised. If you try this, be
- sure to type in a capital Z; DOS, which much of the time converts
- lowercase keyboard inputs into uppercase ones, is case-sensitive here.
-
- Case Closed
- (PC Magazine Vol 5 No 16 Sept 30, 1986 User-to-User)
-
- The GETYES.COM batch branch technique relies on Y or N responses
- and works only if the number of choices is small. A better method for
- branching is to adapt the GETKEY.COM program on which GETYES is based.
- GETKEY reports different IF ERRORLEVEL values for upper- and
- lowercase letters. It's smarter to add a line in GETKEY that will
- convert all lowercase letters to uppercase. To do this, use an ASCII
- word processor or DOS's COPY.COM to create a script called GETFIX,
- containing the lines:
-
- N GETNEW.COM
- A
- MOV AH,0
- INT 16
- AND AL,DF
- MOV AH,4C
- INT 21
-
- RCX
- A
- W
- Q
-
- Then create the GETNEW.COM file by putting GETFIX on the same disk as
- DEBUG and typing:
-
- DEBUG < GETFIX
-
- GETNEW.COM will let you work with just capital-letter values,
- reducing the IF ERRORLEVEL tests by half. The example batch file
- below will let you type in either A, B, or C (or a, b, or c) and will
- then figure out with a minimum of tests which keys you hit.
-
- ECHO OFF
- :MENU
- ECHO ------------------------------
- ECHO Hit A, B, or C (or a, b, or c)
- ECHO -- or hit Q (or q) to quit --
- ECHO ------------------------------
- GETNEW
- IF ERRORLEVEL 82 GOTO OOPS
- IF ERRORLEVEL 81 GOTO END
- IF ERRORLEVEL 68 GOTO OOPS
- IF ERRORLEVEL 67 GOTO C
- IF ERRORLEVEL 66 GOTO B
- IF ERRORLEVEL 65 GOTO A
- GOTO OOPS
- :C
- ECHO YOU HIT A C
- GOTO MENU
- :B
- ECHO YOU HIT A B
- GOTO MENU
- :A
- ECHO YOU HIT AN A
- GOTO MENU
- :OOPS
- ECHO WRONG ...
- GOTO MENU
- :END
-
- While reducing the number of IF ERRORLEVEL tests will speed up
- batch file execution, you can make your batch files run much faster
- by running them out of RAMdisks and arranging the test properly.
- Since batch files search for labels from the top of each batch file,
- put nonessential statements at the bottom (and GOTO them), and put the
- labels that users are most likely to choose nearest the top.
- Finally, don't exit with an :END label at the end of the batch
- file, which is the most time-consuming search of all. Instead,
- execute a dummy batch file. Since DOS doesn't allow nesting of batch
- files, this will drop you to the DOS prompt.
- Editor's Note: ANDing any ASCII value with 223 (hex DF) will
- capitalize lowercase letters and leave uppercase letters alone. The
- logical AND operation works by comparing two values (the example below
- compares 1 bit at a time) and returning a 1 only when both values are
- nonzero.
-
- 1 AND 1 = 1
- 1 AND 0 = 0
- 0 AND 1 = 0
- 0 AND 0 = 0
-
- 223 equals binary 11011111. Capital A (decimal 65) is binary 01000001,
- while lowercase a (decimal 97) is binary 01100001. The AND operation
- on these numbers could be represented as:
-
- 01000001 (65)
- AND 11011111 (223)
- --------
- 01000001 (65)
-
- 01100001 (97)
- AND 11011111 (223)
- --------
- 01000001 (65)
-
- ANDing either a 0 or a 1 with 1 in effect leaves the value alone, and
- ANDing both a 0 and 1 with 0 in effect turns the value into a 0. The
- binary number 11011111 forces the 2^5 bit -- the sixth one from the
- right -- to become a 0 and leaves all the other bits the way they were.
- (The rightmost bit is 2^0; the left most is 2^7.)
- The only difference between a lowercase letter and its capital
- counterpart is that the 2^5 bit is "set" (=1) in the lowercase version.
- ANDing it with 11011111 "unsets" the bit, chaning it to a 0 and
- lowering the ASCII value by 32.
- To reverse the process and turn capital letters into lowercase
- ones, use the logical OR operation to OR a value with 32.
-
- 1 OR 1 = 1
- 1 OR 0 = 1
- 0 OR 1 = 1
- 0 OR 0 = 0
-
- 32 equals binary 00100000. Since ORing either a 1 or a 0 with 0 in
- effect leaves the value alone, and ORing either a 1 or a 0 with 1 in
- effect turns the value into a 1, the binary number 00100000 forces the
- 2^5 bit to become a 1 and leaves all the other bits the way they were.
- This "sets" the unset 2^5 bit in an uppercase letter, changing it
- to a 1 and raising the ASCII value by 32.
-
- 01000001 (65)
- OR 00100000 (32)
- --------
- 01100001 (97)
-
- 01100001 (97)
- OR 00100000 (32)
- --------
- 01100001 (97)
-
- GETNEW.COM is a significant improvement over the previous
- GETKEY.COM routine. Using GETNEW in your batch files will let you
- offer 26 choices -- amost certainly enough -- while keeping the number
- of IF ERRORLEVEL tests to a minimum.
- Of the other batch file enhancement techniques suggested, by far
- teh most important is to run any branching batch file from a RAMdisk.
- the VDISK.SYS "virtual disk" comes free with DOS and is smart,
- flexible, and extremely easy to use. You don't even have to change
- any system board DIP switch settings to take advantage of a RAMdisk's
- speed gain.
- One more note -- DOS in fact does allow batch file nesting. To
- do so, preface the name of the batch file to be nested with COMMAND /C,
- which runs it out of a secondary command processor. (See "Nested FORs"
- PC Mag Vol 5 No 16 Sept 30, 1986 User-to-User below.)
-
-
- Batch Feedback
- (PC Magazine Vol 5 No 21 Dec 9, 1986 User-to-User)
-
- The GETNEW.COM program provides a useful way to implement an
- interactive batch file in which a letter typed on the keyboard sets
- the ERRORLEVEL to its corresponding ASCII value. However, the program
- does not echo the character typed. Since batch files execute slowly,
- even on a hard disk system, an impatient user may repeatedly press the
- key until a response is seen. These extra keystrokes are stored in the
- input buffer and may cause undesired effects once control is passed to
- a program.
- A simple modification of GETNEW that provides feedback to the user
- by echoing the character typed is:
-
- N GETNEW.COM
- A
- MOV AH,0
- INT 16
- OR AL,20
- MOV DL,AL
- MOV AH,02
- INT 21
- MOV AH,4C
- INT 21
-
- RCX
- 10
- W
- Q
-
- (Name this file GETNEW.SCR. Then use DEBUG to create GETNEW.COM by
- typing: DEBUG < GETNEW.SCR.) Since most users leave CapsLock off and
- work with lowercase letters, the program is modified to convert all
- input to lowercase. If uppercase conversion is preferred, replace the
-
- OR AL,20
-
- with
-
- AND AL,DF
-
- The batch file below is a program that uses GETNEW to run any of
- a selection of programs listed on a menu. To speed execution, the menu
- is stored in an ASCII file MENU.TXT (see below) in the root directory.
- This batch file can replace a number of smaller files used to call
- individual programs. Since each batch file replaced uses 4,096
- characters of storage on a hard disk regardless of how small it is,
- the savings in disk storage space can be considerable.
-
- echo off
- :restart
- cls
- prompt
- cd\
- path\
- type MENU.TXT
- getnew
- echo ...Wait...
- if errorlevel=114 goto errmsg
- if errorlevel=113 goto q
- if errorlevel=105 goto errmsg
- if errorlevel=104 goto h
- if errorlevel=103 goto g
- .
- .
- .
- if errorlevel=97 goto a
- :errmsg
- echo Invalid response.
- goto restart
- :a
- echo Running [program a]...
- cd\[subdirectory a]
- [batch instructions to run program a]
- .
- .
- .
- goto restart
- :b
- echo Running [program b]...
- cd\[subdirectory b]
- [batch instructions to run program b]
- .
- .
- .
- goto restart
- :c
- [etc.]
- .
- .
- .
- :q
- cls
- prompt type HELP for menu$_$n$g
-
- Following is the ASCII file MENU.TXT which should be stored in the
- root directory. The file ends after the : on the last line without a
- carriage return, so that the input letter to be echoed will appear on
- the same line as the request.
-
- type to do this
- ------- ----------------
- a run [program a]
- b run [program b]
- c run [program c]
- .
- .
- .
- h run [program h]
- q exit this menu to DOS
-
- When in DOS, type HELP to get back to this menu
- Type letter (a through h or q):
-
- Editor's Note: This modification can come in handy if you run your
- batch files off floppies or slow hard disks. But it's far more
- efficient to create a small RAMdrive when you boot up (the DOS
- VDISK.SYS will handle the job), copy your important batch files to
- the RAMdrive, PATH to it, and execute everything out of memory. The
- technique of using the TYPE MENU.TXT command rather than a string of
- ECHO statements to display a long menu is a good one, as is leaving
- the final carriage return off the last line of the .TXT file that
- acts as a prompt. (Don't omit carriage returns from final ECHO
- commands, however, or DOS won't execute them properly.) The 4K
- minimum file length applies just to XT hard disks under DOS 2.x; an
- AT running DOS 3.x gets away with files half that size.
-
-
- -----------------------------------------------------------------
- Nested FORs
- (PC Magazine Vol 5 No 16 Sept 30, 1986 User-to-User)
-
- Trying to next FOR batch subcommands usually results in a "FOR
- cannot be nested" error message. The solution is to load a COMMAND /C
- secondary command processor before the second FOR. This technique will
- work more than the two levels deep in the example shown below. If you
- try this technique in direct DOS mode (rather than in a batch file),
- use single % signs rather than the double % signs required for batch
- files.
-
- for %%a in (1 2 3) do for %%b in (A B C) do echo %%a %%b
-
- for %%a in (1 2 3) do command/c for %%b in (A B C) do echo %%a %%b
-
- Editor's Note: DOS doesn't seem especially picky about what
- COMMAND /C syntax you use. All of these variables work fine when
- inserted in the example shown above:
-
- COMMAND /C FOR
- COMMAND/C FOR
- COMMAND /CFOR
- COMMAND/CFOR
-
- -----------------------------------------------------------------
- Resounding ECHOs
- (PC Magazine Vol 5 No 16 Sept 30, 1986 PC Tutor)
-
- Several readers pointed out that using ASCII 255 to get DOS 3.1
- to ECHO blank lines (PC Tutor Vol 5 No 10 May 27, 1986), an alternative
- solution (a patch to COMMAND.COM) had already appeared in User-to-User
- Vol 4 No 24 November 26, 1985.
- The COMMAND.COM patch is not a good solution in this case. The
- patch doesn't really solve the problem, since for every new DOS version
- somebody will have to figure out where to put similar new patches.
- ECHO has been fixed in DOS 3.1, so patching COMMAND.COM to
- duplicate the effect of an old bug doesn't make sense. ECHO should
- not act differently if it is followed by one blank space or by two
- blank spaces, as it does in DOS 2.0 through 3.0. The real problem
- with ECHO is its insistence on issuing "Echo is on" and "Echo is off"
- messages. If ECHO did not dish out these useless messages, it would
- simply echo a blank line when entered without a parameter.
- In the case at hand, the person who asked about echoing blank
- lines was involved in maintaining batch files in a corporate setting
- where they are used on many different PCs. Patching COMMAND.COM on
- each of these machines rather than changing the batch files (which
- require periodic redistribution anyway) didn't seem to be a reasonable
- approach. The use of EDLIN, with its redirection of standard input,
- illustrated some valuable techniques that could be applied in other
- circumstances where changes must be made in several different files.
- The recommendation to change the ECHO statements to echo an
- ASCII 255 (which displays as a blank) is not the only good fix,
- however. Several readers pointed out that:
-
- ECHO.
-
- will print a blank lines, as will also
-
- ECHO:
-
- Both are cleaner and much easier to create with most text editors.
- Note that the period and colon must immediately follow ECHO.
- You can also use a slash, backslash, double quote, left or right
- bracket, or a plus sign immediately following the word ECHO. What all
- these characters have in common is that they may not be used in file
- or command names (thus they obviously aren't part of the command),
- they are not delimiters, and they serve no other purpose on a command
- line (as would the angle brackets, for instance). All were tested
- with DOS 3.2 and they work.
- Another reader suggested creating ASCII files containing the text
- to be displayed and using the batch file to TYPE these files to the
- screen after turning ECHO off. This is most useful when creating
- full-screen displays from batch files, since you can put ANSI control
- sequences in the file for moving the cursor around and highlighting.
-
- -----------------------------------------------------------------
- Batch String Comparer
- (PC Magazine Vol 5 No 17 Oct 14, 1986 User-to-User)
-
- DOS makes it easy to control branching by passing parameters into
- batch files form the command line. You can then use IF statements to
- compare such parameters and branch accordingly. But DOS is case
- sensitive, which means that a string N characters long requires 2^N
- IF statements to compare all of the permutations of uppercase and
- lowercase letters. A string containing the three characters ABC would
- require eight IF statements (testing for aBc, ABc, aBC, and so on) to
- exhaust every possible combination. This increases execution time
- dramatically.
- COMPARE.COM compares two strings and ignores the case of the
- alphabetic characters. On return, it sets ERRORLEVEL 255 if both
- strings are equal and ERRORLEVEL 0 if they are not equal or if a
- syntax error has occurred. After executing COMPARE.COM, your batch
- file may take appropriate action with the statement "IF ERRORLEVEL 255
- (do something)."
- To test COMPARE.COM, run the sample COMPTEST.BAT batch file. At
- the DOS prompt type:
-
- COMPTEST hello HELLO
-
- and it will respond with the message:
-
- The strings are equal.
-
- IF ERRORLEVEL is a necessity in large batch files, and this lets
- you use words rather than single characters to trigger branching,
- making things far friendlier.
-
- COMPTEST.BAT:
-
- echo off
- if %2!==! goto oops
- compare %1==%2
- if errorlevel 255 goto match
- echo The strings are not equal.
- goto end
- :match
- echo The strings are equal.
- goto end
- :oops
- echo The format required is:
- echo COMPTEST STRING1 STRING2
- :end
-
-
- COMPARE.BAS:
-
- 100 'COMPARE.BAS: Creates COMPARE.COM.
- 110 PRINT "Checking DATA statements ...."
- 120 FOR B=1 TO 9:FOR C=1 TO 17:READ A$:IF C<17 THEN 140
- 130 Z#=Z#+VAL(A$)
- 140 NEXT:NEXT
- 150 IF Z#=13419 THEN RESTORE:GOTO 180
- 160 PRINT "Wrong number of DATA statements, or error in a big"
- 170 PRINT "number at the end of a line -- check and redo.":END
- 180 FOR B=1 TO 9:FOR C=1 TO 16:READ A$:TTL=TTL+VAL("&H"+A$)
- 190 NEXT
- 200 READ S:IF S=TTL THEN 220
- 210 PRINT "DATA error in line";B*10+260;" -- check and redo.":END
- 220 TTL=0:NEXT:RESTORE
- 230 OPEN "COMPARE.COM" AS #1 LEN=1:FIELD #1,1 AS D$
- 240 FOR B=1 TO 9:FOR C=1 TO 16:READ A$:LSET D$=CHR$(VAL("&H"+A$))
- 250 PUT #1:NEXT:READ DUMMY$:NEXT:CLOSE
- 260 PRINT "COMPARE.COM created."
- 270 DATA BE,81,00,FC,AC,3C,20,74,FB,3C,0D,74,4C,4E,56,5F,1726
- 280 DATA 2B,C9,AC,3C,3D,74,17,3C,20,74,0A,3C,0D,74,3A,E8,1373
- 290 DATA 44,00,41,EB,ED,AC,3C,20,74,FB,3C,3D,75,2B,AC,3C,1749
- 300 DATA 3D,75,26,AC,3C,20,74,FB,4E,56,2B,DB,AC,3C,0D,74,1634
- 310 DATA 0A,3C,20,74,06,E8,1E,00,43,EB,F1,3B,CB,75,11,5E,1519
- 320 DATA B0,FF,F3,A6,74,0C,EB,08,90,B4,09,BA,74,01,CD,21,2085
- 330 DATA B0,00,B4,4C,CD,21,3C,61,72,09,3C,7A,77,05,24,5F,1387
- 340 DATA 88,44,FF,C3,53,79,6E,74,61,78,20,65,72,72,6F,72,1887
- 350 DATA 0D,0A,24,00,00,00,00,00,00,00,00,00,00,00,00,00,59
-
-
- COMPARE.ASM:
-
- compare segment
- ;
- ;program to compare two strings
- ;case of letters will be ignored in the comparison
- ;for use in batch files for comparing strings
- ;
- ;syntax: compare string1 string2
- ;
- ;errorlevel 255 = same string
- ;errorlevel 0 = not same string or syntax error
- ;
- main proc far
- assume cs:compare,ds:compare,es:compare,ss:compare
- org 100h
- doscall equ 21h
- prnt_msg equ 09h
- exit equ 4ch
-
- start:
- mov si,81h
- cld
-
- start_first_string:
- lodsb
- cmp al,' '
- je start_first_string
- cmp al,0dh
- je error
- dec si
- push si
- pop di
- sub cx,cx
-
- get_first_string:
- lodsb
- cmp al,'='
- je equal_sign
- cmp al,' '
- je white_space
- cmp al,0dh
- je error
- call uppercase
- inc cx
- jmp get_first_string
-
- white_space:
- lodsb
- cmp al,' '
- je white_space
- cmp al,'='
- jne error
-
- equal_sign:
- lodsb
- cmp al,'='
- jne error
-
- start_second_string:
- lodsb
- cmp al,' '
- je start_second_string
- dec si
- push si
- sub bx,bx
-
- get_second_string:
- lodsb
- cmp al,0dh
- je end_second_string
- cmp al,' '
- je end_second_string
- call uppercase
- inc bx
- jmp get_second_string
-
- end_second_string:
- cmp cx,bx
- jne no_match
- pop si
- mov al,255
- repe cmpsb
- jz end
- jmp no_match
-
- error: mov ah,prnt_msg
- mov dx,offset synt_msg
- int doscall
-
- no_match:
- mov al,0
-
- end: mov ah,exit
- int doscall
-
- main endp
-
- uppercase proc near
- cmp al,'a'
- jb is_upper
- cmp al,'z'
- ja is_upper
- and al,5fh
- mov [si-1],al
-
- is_upper:
- ret
- uppercase endp
-
- synt_msg db 'Syntax error',0dh,0ah,'$'
-
- compare ends
- end start
-
- -----------------------------------------------------------------
- Batch File Parameters
- (PC Magazine Vol 5 No 19 Nov 11, 1986 PC Tutor)
-
- If you try to prevent the omission of an important batch file
- parameter by using an IF command within a batch file, such as in the
- line:
-
- IF %1==GOTO ERROR
-
- you get a "Syntax Error" from DOS.
- There is a way to check for teh case of a null batch file
- variable. Just put some other character on both sides of the double
- equal sign, such as a slash:
-
- IF /%1==/ GOTO ERROR
- One of the best ways to learn about batch file tricks is by
- exploring the installation programs that software manufacturers often
- ship with their products.
-
- -----------------------------------------------------------------
- Pruning the XTREE
- (PC Magazine Vol 5 No 20 Nov 25, 1986 Power User)
-
- XTREE is the hard disk organizer of choice, but its chief
- shortcoming is the mandatory read of the entire directory structure.
- This problem can be overcome by using the DOS 3.1 SUBST command,
- however. SUBST lets you substitute a drive letter for a path
- specification, and the drive letter is acceptable to XTREE. Invoke
- XTREE from a batch file called XTRE.BAT:
-
- ECHO OFF
- IF P%1==P GOTO FULL
- SUBST D: /D > NUL
- SUBST D:=%1
- XTREE D:
- GOTO END
- :FULL
- XTREE
- :END
-
- The first SUBST turns off any previous SUBSTitutes. The second assigns
- the drive letter D to a pathname specified when invoking the batch
- file. For example, to examine the subdirectory \DOS\UTIL, enter:
-
- XTRE \DOS\UTIL
-
- Or, to work with the current default directory:
-
- XTRE
-
- In either case, once in XTREE, you can change back to a full directory
- display by logging on to the actual drive.
- Notice that the file begins checking to see if you included a
- pathname. If not, it jumps to FULL, and XTREE wakes up reading the
- entire directory structure.
- Editor's Note: This is one of the more inventive applications
- for SUBST. Be forewarned, however, that although you may use any
- drive letter (A through Z) as the substitute "drive," DOS normally
- assumes that the last drive is E:. If A: through E: are already taken
- up by real drives plus a RAMdisk, you'll have to add a new line to
- your CONFIG.SYS file. The line reads:
-
- LASTDRIVE = x
-
- where x is any letter, A through Z. The value of x becomes the
- highest driver letter that DOS will recognize.
-
- -----------------------------------------------------------------
- Menu Making Made Easy
- (PC Magazine Vol 5 No 20 Nov 25, 1986 User-to-User)
-
- Using the ECHO command to provide prompts or a menu in a batch
- file is handy if the text is short. But try to display several lines
- or a long menu, and ECHO can be frustratingly slow. This is even more
- irritating in batch files that routinely loop back and redisplay such
- menus.
- The solution is to write a short .COM file that uses function 9
- of interrupt 21. The only read drawback is that this technique won't
- let you display a $, since DOS uses this hex character 24 to mark the
- end of the output string. To create a MENU.COM file, get into DEBUG
- and type in the script shown below, substituting your own text for the
- dummy "Menu Selection 1" and "Menu Selection 2".
- To have MENU.COM display more than just two lines, precede each
- line with "DB'" and follow each with the line:
-
- DB 0D 0A
-
- However, make sure the very last line of text (and only that line)
- contains an extra hex 24, which is the $ that tells DOS your text is
- done:
-
- DB 0D 0A 24
-
- When you've finished entering text and have typed the 24, hit the Enter
- key twice. They you tell DEBUG how long the file is by typing RCX and
- entering the length of the file in hex. You can figure out the length
- by subtracting hex 100 from the hex number directly above the RCX. In
- the example below, this number is 12E, so 12E - 100 = 2E. Once you're
- done, get into DOS and type MENU to display the text you've entered.
-
- A>DEBUG
- -N MENU.COM
- -A 100
- XXXX:0100 MOV DX,0109
- XXXX:0103 MOV AH,09
- XXXX:0105 INT 21
- XXXX:0107 INT 20
- XXXX:0109 db 'Menu Selection 1
- XXXX:0119 db 0D 0A
- XXXX:011B db 'Menu Selection 2
- XXXX:012B db 0D 0A 24
- XXXX:012E
- RCX
- CX 0000
- :2E
- -W
- Writing 002E bytes
- -Q
-
- Editor's Note: MENUMAKR.BAS automates the process. It isn't
- fancy, but it will center lines if you want, and it handles all the
- file creation details for you. Since it always names the output file
- MENU.COM, if you use MENUMAKR more than once, be sure to remove any
- existing MENU.COM programs you may have created previously.
-
- 100 'MENUMAKR.BAS
- 110 CLS:DEF FNST$(Z)=MID$(STR$(Z),2)
- 120 DIM A$(24):A=1:TOTAL=0
- 130 PRINT "Enter your line of text #";FNST$(A);":"
- 140 LINE INPUT A$(A)
- 150 IF LEN(A$(A))>79 THEN A$(A)=LEFT$(A$(A),80):GOTO 220
- 160 PRINT "Want it centered (Y/N)?"
- 170 I$=INKEY$:IF I$="" THEN 170
- 180 IF INSTR("YyNn",I$)=0 THEN BEEP:GOTO 170
- 190 IF INSTR("YyNn",I$)>2 THEN 220
- 200 A$(A)=STRING$(40-INT(LEN(A$(A))/2),32)+A$(A)
- 210 PRINT STRING$(2,30);A$(A);CHR$(31)
- 220 A$(A)=A$(A)+CHR$(13)+CHR$(10)
- 230 IF A=24 THEN 290 ELSE A=A+1
- 240 PRINT CHR$(30);"Add any more text (Y/N)?"
- 250 I$=INKEY$:IF I$="" THEN 250
- 260 IF INSTR("YyNn",I$)=0 THEN BEEP:GOTO 250
- 270 IF INSTR("YyNn",I$)>2 THEN 290
- 280 PRINT CHR$(30);:GOTO 130
- 290 OPEN "MENU.COM" FOR OUTPUT AS #1
- 300 FOR B=1 TO 9:READ C:PRINT #1,CHR$(C);:NEXT
- 310 FOR B=1 TO A-1:PRINT #1,A$(B);:NEXT
- 320 PRINT #1,CHR$(36):CLOSE:END
- 330 DATA 186,9,1,180,9,205,33,205,32
-
- -----------------------------------------------------------------
- Capital Idea
- (PC Magazine Vol 5 No 20 Nov 25, 1986 User-to-User)
-
- DOS's IF batch-processing subcommand is case sensitive. This
- means that for each string comparison, you need two tests -- one for
- uppercase and one for lowercase -- such as:
-
- IF %1==TEST ECHO This is a match.
- IF %1==test ECHO This is a match.
-
- Even this redundant test does not guarantee a match if the string
- you enter is a mixture of uppercase and lowercase letters (as in Test
- or TeSt or TEst). This can easily happen if the string you enter is a
- city or a person's name or an oddly capitalized computer company -- or
- if you lean too long on the Shift key.
- DOS 2.1 and DOS 3.1 store user-entered replaceable parameters in
- two entirely different places: DOS 2.1 stores them in the critical
- error-handling segment, and DOS 3.1 stores them just below the
- environment. Because of this, two different programs -- CAPS2.COM and
- CAPS3.COM -- are required to remove the case sensitivity.
- Use the CAPSx.SCR file that applies to the version of DOS you are
- using and at the DOS prompt enter either:
-
- DEBUG < CAPS2.SCR
-
- or
-
- DEBUG < CAPS3.SCR
-
- Then insert CAPSx.COM at the beginning -- or just after ECHO OFF
- and CLS -- of your batch files and delete the duplicate IF string1==
- string2 commands. For example, a DOS 3.1 batch file called TEST.BAT
- that tested to see whether a user entered "MicroPro" would look like
- this:
-
- ECHO OFF
- IF %1!==! GOTO OOPS
- ECHO You entered %1
- CAPS3
- ECHO CAPS3.COM turned it into %1
- IF %1==MicroPro ECHO It works
- GOTO END
- :OOPS
- ECHO Enter TEST MicroPro
- :END
-
- CAPS2.SCR:
-
- A
- MOV AX,[14]
- ADD AX,B2
- MOV DS,AX
- MOV SI,A
- CMP BYTE PTR [SI],0
- JZ 120
- CMP BYTE PTR [SI],61
- JB 11D
- CMP BYTE PTR [SI],7A
- JA 11D
- AND BYTE PTR [SI],5F
- INC SI
- JMP 10B
- INT 20
-
- RCX
- 22
- N CAPS2.COM
- W
- Q
-
-
- CAPS3.SCR:
-
- A
- MOV AX,[2C]
- SUB AX,C
- MOV DS,AX
- MOV BX,A
- ADD BX,10
- MOV SI,BX
- CMP BYTE PTR [SI],3A
- JNZ 10B
- INC SI
- CMP BYTE PTR [SI],5C
- JNZ 10B
- CLD
- LODSB
- CMP AL,0
- JNZ 11C
- CMP BYTE PTR [SI],0
- JZ 136
- CMP BYTE PTR [SI],61
- JB 133
- CMP BYTE PTR [SI],7A
- JA 133
- AND BYTE PTR [SI],5F
- INC SI
- JMP 121
- INT 20
-
- RCX
- 38
- N CAPS3.COM
- W
- Q
-
- -----------------------------------------------------------------
- Blank Lines with ECHO
- (PC World November 1986 Star-Dot-Star)
-
- The ECHO command behaves differently with DOS 3.1 than it does
- with DOS 2.1. Under DOS 2.1, an ECHO command followed by several
- space characters would put a blank line on the screen. DOS 3.1,
- however, ignores spaces and responds by displaying the current ECHO
- status.
- A simple way to get the better of DOS and echo a blank line is
- to use the ECHO command followed by a space and ASCII character 255.
- To create this character, hold down the Alt key and press the digits
- 255 on the numeric keypad, then release the Alt key. Although you
- cannot see the difference between ASCII 255 and a space, DOS will not
- consider the line blank and will display a blank line as intended.
- Some word processors cannot accept the Alt-255 character. Thus,
- you may have to use the DOS EDLIN program to put the character into
- your batch files.
-
- -----------------------------------------------------------------
- Spacing Out a Batch File
- (PC World November 1986 The Help Screen)
-
- A user inadvertently inserted a space in a batch file -- he
- accidentally placed a space between the second period and the first
- percent sign in the line:
-
- IF NOT .==.%1 GOTO %1
-
- rendering the line ineffective. His solution was to place the first
- occurrent of the replaceable DOS parameter %1 to the left of the first
- period and the double equal signs. The line worked, even with spaces
- between the %1 and the period.
- Another line in the batch file, IF %1.==. GOTO HELP, also had a
- replaceable DOS parameter to the left of the double equal signs.
- Although this line will function correctly, it raises an interesting
- point about the placement of DOS's replaceable parameters. The location
- of the replaceable parameter is all-important, and a batch file's
- conditional test for a blank DOS parameter should use:
-
- if x==%1x command
-
- rather than:
-
- if %1x==x command
-
- because if the string to the right of the == matches the first
- character of the left string but the left string is longer, DOS will
- execute command incorrectly. You can demonstrate the bug by creating
- two different batch files, A.BAT and B.BAT, and then typing the line:
-
- IF NOT CONCEPT==CONC A B
-
- and pressing Enter. Because CONCEPT is not equivalent to CONC, DOS
- should perform A. Instead, it selects B. Although DOS 3.0 and later
- versions don't exhibit this bug, play it safe and always use the
- proper syntax. And watch those spaces.
-
- -----------------------------------------------------------------
- Subdirectory Navigators
- (PC Magazine Vol 5 No 21 Dec 9, 1986 User-to-User)
-
- VAX mainframes offer several predefined symbols that greatly
- simplify movement through a hierarchical directory structure: UP,
- DOWN, OVER, and HOME. These pseudo-commands aren't significantly
- faster than VAX/VMS's SET DEFAULT command, but they are much more
- logically oriented.
- Four batch files called UP.BAT, DOWN.BAT, OVER.BAT, and HOME.BAT
- can be stored on a RAMdisk and used as if they were actual DOS
- commands. To go to the parent directory (the one up above the present
- directory), just type UP and hit Enter. To go to a subdirectory called
- DOS (located down below the present directory), just type DOWN DOS.
- Use OVER to move from the present directory to one having the same
- parent (move over to a directory on the same level). HOME will return
- you to the root directory. This is UP.BAT:
-
- ECHO OFF
- CD..
- CD
-
- (The CD command lacking an argument simply displays the current
- directory.) This is DOWN.BAT:
-
- ECHO OFF
- IF "%1" == "" GOTO NODRSPEC
- CD %1
- CD
- GOTO END
- :NODRSPEC
- ECHO Move down to where?
- :END
-
- This is OVER.BAT:
-
- ECHO OFF
- IF "%1" == "" GOTO NODRSPEC
- CD..\%1
- CD
- GOTO END
- :NODRSPEC
- ECHO Move over to where?
- :END
-
- And this is HOME.BAT:
-
- ECHO OFF
- CD\
- CD
-
- When using DOWN.BAT or OVER.BAT, be sure to enter the name of the
- subdirectory where you want to end up. If you don't specify one, the
- batch file will ask you where you want to go. (VAX symbol commands at
- work are not nearly so polie; they respond with a ver sarcastic
- "Really, to where?" prompt.)
- If you are using a RAMdisk, you should copy these files to it.
- If you are not using a RAMdisk, be sure to place the batch files on a
- directory specified by the PATH command in your AUTOEXEC.BAT file.
-
- -----------------------------------------------------------------
- Printer Controls From Batch Files
- (PC Magazine Vol 5 No 22 Dec 23, 1986 Power User)
-
- A word processor can put an IBM Proprinter into near-letter-quality
- mode and leave it there when you exit to DOS. This can be annoying if
- you then wish to print out some files in draft quality mode. To reset
- the printer to draft mode, you could add the following line to your
- word processor batch file (immediately after the line calling up the
- word processor):
-
- TYPE DRAFT.ASC > LPT1:
-
- The file DRAFT.ASC contains the following line:
-
- <ESC>I0
-
- This escape code is the command to tell the printer to go to draft
- mode. The <Esc> must be created by a text editor that lets you embed
- control characters in text. With WordStar or SideKick, for example,
- you would type Ctrl-P <Esc>. In WordStar, this will show on-screen
- as ^[. If you type the file to the screen in DOS, the escape code
- will not show at all.
- With this line added to your batch file, if the printer is off
- when you exit the program, DOS will respond with a "Write fault error"
- and the standard "Abort, Retry, or Ignore" option. You can then choose
- the abort option or turn the printer on and choose retry instead.
- One simple extension of this method is to create a series of such
- batch files for different modes (NLQ, condensed, draft). Then you can
- conveniently switch between modes when printing ASCII files from DOS.
- Editor's Note: To take this one step further, you can create
- batch files that will set the printer mode and start printing with a
- single command. For example, if NLQ.BAT reads:
-
- TYPE NLQ.ASC > LPT1:
- TYPE %1 > LPT1:
-
- and NLQ.ASC contains the escape sequence for NLQ mode for your printer,
- then you can set the printer and start printing with the simple command
-
- NLQ filename
-
- To avoid surprises, you might want to choose a "standard" setting
- for the printer and add the appropriate command for that setting at the
- end of each batch file.
-
- -----------------------------------------------------------------
- BASIC Batch Enhancements
- (PC Magazine Vol 5 No 22 Dec 23, 1986 User-to-User)
-
- This system creates a batch file that can access all of the
- subdirectories on your disk. The DIRSTART.BAT file searches the disk
- and writes a list of the subdirectory names into a file called
- DIRS.DAT. It then runs the DIRS.BAS program, which processes the
- contents of DIRS.DAT and creates the DIRS.BAT batch file. DIRS.BAT
- will contain each of your subdirectory names, preceded by two
- replaceable parameters, and will run commands across your entire disk,
- such as:
-
- DIRS DIR /W
-
- A similar program, DIRS2.BAS, works like DIRS.BAS except that it places
- the replaceable parameters in different places (the second goes after
- the subdirectory name), which allows wildcard directory searches and
- operations such as:
-
- DIRS2 DIR *.COM
-
- If you try DIRS2.BAS, be sure to change the last line in the
- DIRSTART.BAT batch file that runs it, from BASICA DIRS to BASICA DIRS2.
- The following are some illustrations of this technique:
-
- DIRS DSORT N
-
- uses one of the programs in The Norton Utilities to sort all
- subdirectories by filename,
-
- DIRS2 DIR *.DOC
-
- displays all of your .DOC filenames,
-
- DIRS2 DEL *.BAK
-
- deletes all of the .BAK files in all your subdirectories, and -- try
- this with caution --
-
- DIRS2 DEL *.*
-
- erases all files but leaves your subdirectories intact.
-
-
- DIRSTART.BAT:
- echo off
- echo Processing disk ....
- chkdsk/v | find "Directory" > DIRS.DAT
- basica dirs rem Change to "basica dirs2" for DIRS2.BAS
-
-
- 100 'DIRS.BAS
- 110 DIM A$(256):DIM B$(256)
- 120 OPEN "DIRS.DAT" FOR INPUT AS #1
- 130 OPEN "DIRS.BAT" FOR OUTPUT AS #2
- 140 PRINT #2,"ECHO OFF"
- 150 LINE INPUT #1,A$
- 160 B$=MID$(A$,11,40)
- 170 PRINT #2,"%1";" ";"%2";" ";B$
- 180 IF EOF(1) GOTO 190 ELSE 150
- 190 CLOSE:SYSTEM
-
-
- 100 'DIRS2.BAS
- 110 DIM A$(256):DIM B$(256)
- 120 OPEN "DIRS.DAT" FOR INPUT AS #1
- 130 OPEN "DIRS2.BAT" FOR OUTPUT AS #2
- 140 PRINT #2,"ECHO OFF"
- 150 LINE INPUT #1,A$
- 160 B$=MID$(A$,11,40)
- 170 PRINT #2,"%1";" ";B$;
- 180 IF LEN(B$)>3 THEN 200
- 190 PRINT #2,"%2":GOTO 210
- 200 PRINT #2,"\";"%2"
- 210 IF EOF(1) GOTO 220 ELSE 150
- 220 CLOSE:SYSTEM
-
- Editor's Note: Once you've used CHKDSK /V | FIND "Dir" > DIRS.DAT
- to create the list of subdirectories, rather than write a BASIC program
- you can use the search-and-replace mechanism of your word processor to
- create batch files such as the two mentioned here. This technique
- shows the real brute-force power of DOS, especially when it comes to
- replaceable parameters. Remember to have BASIC handy when you run
- these, or have it in a subdirectory that's included in your PATH. You
- can also use SWEEP.COM (PC Mag Vol 4 No 23) to do many of these jobs
- faster and more elegantly.
-
- -----------------------------------------------------------------
- Don't Tread On Me
- (PC Magazine Vol 5 No 22 Dec 23, 1986 User-to-User)
-
- Software vendors often include an AUTOEXEC.BAT file on their
- distribution disks or provide an installation program that creates one.
- By merely copying the distribution disk (using COPY *.*) to your hard
- disk root directory or simply installing the program, you might wipe
- out your own carefully designed pre-existing AUTOEXEC.BAT file.
- Although installing each software package in its own directory can
- reduce this risk, the method is not foolproof. To eliminate the risk
- entirely, never use AUTOEXEC.BAT as the real name for the sequence of
- commands you want to execute on start-up.
- Since the AUTOEXEC.BAT file is no different from any other file
- except for its name, and since any .BAT file can execute another .BAT
- file, you AUTOEXEC.BAT file can contain one simple, easy-to-remember
- command: STARTUP.BAT. STARTUP.BAT contains all the commands that
- would normally be in AUTOEXEC.BAT.
- You never have to worry then about blowing away your start-up
- routines by overlooking an AUTOEXEC.BAT file on a distribution disk,
- or an installation program that creates its own. Furthermore, the
- name STARTUP.BAT itself is an obvious clue as to what AUTOEXEC.BAT
- should contain if you ever need to re-create it.
- Editor's Note: Some programs routinely corrupt both AUTOEXEC.BAT
- and CONFIG.SYS. It was once easy to spot this, since programs would
- install themselves through long batch files that you could read and
- change with a word processor. But many programs now use .COM and .EXE
- files to do the installation.
- Another elegant protection solution is to change COMMAND.COM so
- that it will look for a batch file with a name other than AUTOEXEC.BAT.
- In fact, the first file COMMAND.COM tries to execute doesn't even have
- to end in .BAT. To try this, make a copy of COMMAND.COM and type:
-
- DEBUG COMMAND.COM
-
- Find out how long your version of COMMAND.COM is by typing RCX and
- hitting the Enter key twice. DEBUG will respond by printing the
- letters CX and then the file's length in hex. For instance, in DOS
- 3.1, you'd see:
-
- CX 5AAA
-
- Then search for AUTOEXEC.BAT by typing in:
-
- S 100 5AAA "AUTO"
-
- (substituting the actual length for other versions of COMMAND.COM that
- DEBUG prints after the CX). DEBUG will then print the address of the
- beginning of the name AUTOEXEC.BAT, which in DOS 3.1 would look like:
-
- 5506:130F
-
- (Ignore the four hex numbers on the left; they'll vary from system to
- system, and they don't matter here.)
- AUTOEXEC.BAT is 12 characters long (11 for the filename and 1 for
- the period before the extension), so you have to remember to pad out
- the extra spaces if the new name you replace it with has fewer than 12
- characters. To replace AUTOEXEC.BAT with STARTUP, under DOS 3.1 type:
-
- E 130F "STARTUP "
-
- To check your work, type:
-
- D 130F
-
- and make sure you've written over all traces of AUTOEXEC.BAT.
- To save the modified COMMAND.COM, type:
-
- W
-
- followed by:
-
- Q
-
- to end the DEBUG session.
- Then rename your old AUTOEXEC.BAT file to STARTUP and reboot.
- However, if you don't like changing COMMAND.COM, the next best
- safeguard is to keep a subdirectory called \BAKUP that contains your
- AUTOEXEC.BAT, COMMAND.COM, and CONFIG.SYS files. If new programs
- obliterate your old main startup files, you can always type:
-
- COPY \BAKUP\*.* \
-
- -----------------------------------------------------------------
- Aborting AUTOEXEC.BAT
- (PC Magazine Vol 5 No 22 Dec 23, 1986 User-to-User)
-
- Sometimes you don't want to run your hard disk AUTOEXEC.BAT. A
- combination of resident programs loaded by your AUTOEXEC.BAT might
- cause your machine to hang. Or you might not want to run a product
- your AUTOEXEC.BAT installs (for example, you might not want to bring
- up the PC Network before doing backups).
- In either case, one solution is to boot off a floppy disk in
- drive A:. Or you can continuously press Ctrl-Break while your machine
- is booting, hoping your AUTOEXEC.BAT will abort before the critical
- instructions occur. Either solution is fine if you run into the
- problem only once in a while, but neither is ideal.
- A far better solution is to use a small program called KBFLAG.COM
- to monitor your keyboard as you boot up and send a code to your
- AUTOEXEC.BAT file that an IF ERRORLEVEL instruction can trap. To
- create the KBFLAG.COM program, type in the following KBFLAG.SCR script,
- using the DOS COPY CON command or any pure-ASCII word processor:
-
- N KBFLAG.COM
- A
- MOV AX,40
- MOV DS,AX
- MOV AL,[17]
- MOV AH,4C
- INT 21
-
- RCX
- C
- W
- Q
-
- Be sure to leave a blank line above RCX and hit the Enter key at the
- end of each line, especially the last one. Once you install this
- program, you can press one single key while your machine is booting
- to avoid running your AUTOEXEC.BAT.
- Then, add these two lines at the very beginning of your
- AUTOEXEC.BAT:
-
- KBFLAG
- IF ERRORLEVEL 1 GOTO
-
- Note: The second statement is syntactically incorrect. When ERRORLEVEL
- is nonzero, you will get a message about a missing label (since the
- GOTO does not specify a label). Ignore the error message. The
- important thing is that the remainder of the .BAT file will not be
- executed.
- KBFLAG simply sets the DOS ERRORLEVEL to the value of the KBFLAG
- in the ROM BIOS area. You can use different keys to trigger KBFLAG.
- These keys, and the codes read by IF ERRORLEVEL, are:
-
- 1 = Right Shift
- 2 = Left Shift
- 4 = Ctrl key
- 8 = Alt-Shift
- 16 = ScrollLock
- 32 = NumLock
- 64 = CapsLock
- 128 = Ins
-
- For example, you can avoid running AUTOEXEC.BAT if you press and hold
- the Shift key while your machine boots, or if you simply press NumLock
- while your CONFIG.SYS is running. The latter technique is preferable
- in some situations. (Long CONFIG.SYS files can run for over a minute
- -- you wouldn't want to have to hold the Shift key down that long.)
- You can add the above key values together. For example, if you
- wanted the trigger to be the Right and Left Shift keys plus the Ins
- key (toggled on) you would use an ERRORLEVEL trap of 131 (1+2+128=131).
- You could also make your batch file test for several ERRORLEVELs
- or act differently when different keys are pressed. For example,
- CapsLock could mean abort the AUTOEXEC.BAT, while NumLock could do
- everything but load a couple of resident programs. Of course, KBFLAG
- can be used in any .BAT file, not just your AUTOEXEC.BAT.
- Editor's Note: Stopping the execution of a batch file by forcing
- a syntax error works, but there's a much simpler way to avoid running
- the batch file. Make the first two lines of your AUTOEXEC.BAT:
-
- KBFLAG
- IF ERRORLEVEL 128 GOTO :END
-
- and then add a line at the very end of the batch file:
-
- :END
-
- Then you can avoid running your AUTOEXEC.BAT file by toggling the Ins
- key when you boot up. KBFLAG will send a 128 to the IF ERRORLEVEL
- trap, which will branch to the :END label. This is far more elegant
- than pounding on the keyboard, which can generate 301 bootup errors
- and force you to hit the F1 key and then restart the whole operation.
- Using the Ins toggle means you can branch out of the program with one
- simple key press, or start normally by keeping your fingers off the
- keyboard.
-
- -----------------------------------------------------------------
- AUTOEXEC Autopilot
- (PC World December 1986 Star-Dot-Star)
-
- A number of different computers, all configured differently, are
- used in an office. Some have two floppy drives, some have one, some
- have a hard disk, some do not. This AUTOEXEC.BAT file determines which
- drive letter refers to the RAM disk, so that the start-up process
- operates properly on every machine.
- The techniques relies on the fact that when the system is turned
- on, there are no files in the RAM disk. The first IF EXIST command
- tests for the presence of files on drive C:. If there are none, drive
- C: is the RAM disk. If a file is present, drive C: must be a hard
- disk, so the batch file branches to :isDhard and checks whether drive
- D: has any files. If there is no file, drive D: is the RAM disk; if
- there is, drive E: is the RAM disk.
- Once the drive letter of the RAM disk is determined, the batch
- file uses the SET command to assign that letter to a variable that can
- be used by other commands within the batch file. The following command
- uses that variable as the drive letter and copies a second batch file
- to the RAM disk. The second batch file contains the remainder of the
- start-up commands and executes from the RAM disk. When the first batch
- file transfers execution to the second, it passes the RAM disk drive
- letter on as a command line parameter for use by other commands within
- the second file.
-
- echo off
- cls
- if exist c:*.* goto isDhard
- echo No fixed disk present
- set ramdisk=C:
- goto :more
- :isDhard
- if exist d:*.* goto D
- echo Fixed disk is drive C:
- set ramdisk=D:
- goto more
- :D
- echo Fixed disk is drive D:
- set ramdisk=E:
- :more
- echo RAM disk is drive %ramdisk%
- copy a:autobat2.bat %ramdisk% >nul
- %ramdisk%
- autobat2 %ramdisk%
-
- Editor's Note: If you often use different PC's, and one has more
- than two hard disks or a hard disk that is divided into more than two
- volumes, you must notify AUTOBAT.BAT to also check those drives for
- files.
-