The magazine of the Melbourne PC User Group

Bats in the Belfry
Tom Coleman

Although each sector on your hard disk is 512 bytes, DOS uses a minimum of four of them as the smallest group it recognises. That's 2 kB of disk space that your smallest file is using. These groups of sectors are known as dusters.

Batch files frequently use less than 512 bytes but DOS blindly allocates 2 kB regardless. The balance of these files to 2 kB is just wasted.

Actually that is not quite true. Earlier versions of DOS (Pre 3.1) use 4 kB or even 8 kB as a minimum file size.

There is another time it is not true even with recent versions of DOS (I am not sure about DOS 5.0). Providing the hard disk is bigger than 16 MB then the cluster is 2 kB. If the hard disk is smaller than 16 MB then the cluster is 4 kB.

This means that you should partition your 40 MB hard disk into 2 x 20 MB not 32 MB and 8 MB which is what you will get if you accept the first partition to be the maximum size under DOS 3.3 or less.

An 8 MB hard disk will have all of the files wasting the balance to the next 4 kB. This is a lot more wasted space.

You get less files per megabyte from a hard disk less than 16 MB.

The following batch file (contained in LOTSOF.BAT) is an attempt to economise on disk space by putting several simple batch commands into one file.

echo off 
If "%1"--"" goto nogood 
cls 
If %1= WP goto wp 
If %1= LOTUS goto lotus 
If %1= PDX goto pdx
cls 
Echo %1 is not a legal parameter 
:Nogood 
cls 
Echo. The syntax for this batch file is: 
Echo. 
Echo.   Lotsof File 
Echo. 
Echo. Where File is one of the following 
Echo.   WP to start Word Perfect 
Echo.   LOTUS to start Lotus 
Echo.   PDX to start Paradox Echo. 
PAUSE 
goto end 
:WP
C: 
CD\WP51 
WP 
goto end 
:LOTUS
c: 
cd\LOTUS 123 
goto end 
:PDX 
C: 
CD\PARADOX3 PARADOX3 
:END

The purpose of this batch file is accomplished by lines 4-6. These lines recognise the word that follows the command LOTSOF and sends control off to the appropriate label where the next few lines execute start up commands.

The second line

If "%1"="" goto nogood

sends control off to a few lines of help if nothing (i.e. "") was the word following the command (i.e. %1).

A word of explanation. DOS assumes that the first word on a line is a command unless it is one of a few special words such as REM or ECHO. Any word that follows a space or sometimes a comma or certain other characters depending on the circumstances is regarded as a parameter or something for the command to work on or with.

In order for DOS to keep track of these things it numbers them. Being a computer it numbers the first thing on the command line 0, that is usually the command. The next word is numbered 1, the next is 2, and so on.

In order to be able to identify these from other numbers DOS puts a special mark in front of them - a % mark.

Thus the second word on the command line is %1 the next is %2 and so on.

Coming back to our batch file. You start it up with the first word on the command line - the filename LOTSOF. You should then put in WP or PDX or whatever names you have decided on for your batch file. This makes WP the second thing on the command line which DOS recognises as %1.

If you did not put anything after the command LOTSOF then there is a string of characters of zero length after the command. Strings of characters are enclosed by quotation marks. So two quotation marks with not even a space between them is a zero length string.

So

If "%1"= "" goto nogood

means if the second word on the command line is a zero length string go to the line with the label NOGOOD.

A label is simply a place in the batch file identified with a string of letters or a word preceded by a colon (:) It is used to direct control to a particular set of commands or to bypass others.

So far the second line has detected the presence or absence of a word following the command. If there is nothing then control goes off to an error routine that displays information about the correct syntax. The next few lines test for various legal parameters. If none are found then the error message "Not a legal parameter" is printed and control goes to the same error message which gives advice about the correct syntax.

All in all not a very magic batch file but with just those three parameters it would save you 4 kB of disk space. With ten parameters instead of ten batch files you would save 18 kB.

The real problem with all of this is remembering all the different parameters. Here is a variation of the above that will save you the trouble of remembering.

echo off 
echo
=====================================
:start 
echo Do you want to run WordPerfect 
question 
if errorlevel 1 goto wp 
echo Do you want to run Lotus 123 
question 
if errorlevel 1 goto lotus 
echo Do you want to run Paradox 
if errorlevel 1 goto paradox

........ add more lines here if you like

echo Do you want to end this batch file 
question 
if errorlevel 1 goto end 
goto start 
:end

The problem with this is that it leads you through every choice available until you get to the one you want. Ten choices might be more than flesh and blood could stand.

This also requires that you have the file QUESTION.COM available. [ Download from link ]

If you have QUESTION.COM then you might have QUERY or QUERY2. It pays to have a suit of batch file utilities and ifs fun learning how to use them.

QUERY.COM is smarter than QUESTION.COM in some respects. It will accept and recognise almost any character. The problem being that you have got to test for every possible choice. Let's do a version using QUERY.COM

:start 
cls 
echo off 
echo   A   WORD PERFECT
echo   B   LOTUS
echo   C   PARADOX
echo   Q   QUIT
query2 "AaBbCcQq" "Enter letter chosen"
if errorlevel =114 goto wrong
if errorlevel =113 goto end
if errorlevel =99  goto paradox
if errorlevel =98  go to Lotus
if errorlevel =97  goto WP 
if errorlevel =81  goto end 
if errorlevel =68  goto wrong 
if errorlevel =67  goto paradox
if errorlevel =66  goto lotus 
if errorlevel =65  goto WP 
:wrong
echo That choice is not valid ..Try again. 
goto start

QUERY.COM and QUERY2.COM both work by setting the errorlevel to the ASCII value of the key pressed. QUERY.COM will accept anything but QUERY2 is a bit more discerning and restricts the input. The WRONG label is there in case a key press slips by QUERY2.COM. It should not but I understand it is not completely idiot proof. You need it for QUERY.COM any way as it will accept any input.

As you can see there is a requirement to test for both upper and lower case entries.

As the errorlevel test is for the stated number and all higher values the line that tests for 114 is testing for a lowercase r and above. The next line tests for q. Then the next line tests for any letter above d.

There are plenty of interesting batch file utilities on the bulletin boards and in the Public Domain Library.

We teach our students on our DOS courses how to use them. We give them disks full of files to practice on.

Read through a few batch files. If you read some of the .DOC files that come with the Utilities you will find that you can see a better way of doing this batch file. You can make it more friendly, more flexible, more capable.

It goes to show that there is more than one way of skinning a bat.

Try it.

Reprinted from the August 1991 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]