Category : Batch File Utilities - mostly for DOS
Archive   : BUBBA.ZIP
Filename : BUBA.DOC

 
Output of file : BUBA.DOC contained in archive : BUBBA.ZIP







************************
B U B A

Bill's
Unique
Batch
Arsenal
***********************

A free, public-domain group of utilities
designed to make batch files more capable.

by Bill Reamy






This archive should contain the following files:
DISKSIZE.EXE Reports (in ErrorLevel) the size of a disk.
FILEFITS.EXE Checks the size of a particular file.
FILESIZE.EXE Reports (in ErrorLevel) the size of a file.
INPUT.EXE Places user input in an environment variable.
SELECTOR.EXE A point & shoot file picker .
BUBA.DOC This Documentation.

If you want a quick help screen for any of these programs, just run the
program with just ? as a parameter. For example: FileFits ?

*****************************************************************************
* DISCLAIMER: These programs are provided as is. They seem to work on my *
* system without causing damage. I do NOT guarantee they will do the same *
* on your system. I haven't (can't) tested these programs with all versions *
* of DOS, and I can't guarantee they won't lock up your computer, destroy *
* data or make you impotent or anything like that. But I would like to hear *
* about any problems you have. *
*****************************************************************************




If you have comments, suggestions, questions, or (gasp) complaints, you
can E-mail me at either of these addresses:
GEnie Mail: W.Reamy
CompServe: 71660,3072
Or, if you prefer real paper (paper, what's that?), drop me a line at:
Bill Reamy
9426 Dubarry Ave.
SeaBrook Md. 20706




The programs in this package are designed to extend, rather than replace
the many fine batch utility packages currently available. You won't find yet
another screen color manipulator here. If you don't yet have a good general
purpose batch file enhancer package, I suggest you look into getting one.
PC Magazine has put out some good utilities in this department, and Peter
Norton has blessed us with some really excellent stuff to add capabilities
and pizzaz to batch files. There are certainly many other good packages, both
commercial and shareware, that can let you harness the power of batch files.

I wrote most of these programs when I was writing a batch file and got
stuck because I didn't have a way of doing a particular task. That's why
the 'U' in BUBA stands for Unique. If anyone has written similar programs,
I am unaware of it. These programs probably won't get used in all (or
even most) of your batch files, but when they are needed, they can prove
to be very valuable indeed.

****************
**** DiskSize.exe ***********************************************************
****************

DiskSize can let your batch program determine the actual size of a floppy
(or hard) disk. For instance, if you have a 1.2meg 5 1/2" floppy drive, but
the disk currently in it is a 360k floppy, DiskSize can spot it as being 360k.

Usage.......DISKSIZE [d:]
d: is drive you specify, and it is optional.

Returns.....ErrorLevel 1: 360k 5.25"
ErrorLevel 2: 720k 3.5"
ErrorLevel 3: 1.2m 5.25"
ErrorLevel 4: 1.44m 3.5"
ErrorLevel 128: 11-20meg Hard Disk
ErrorLevel 129: 21-40meg Hard Disk
ErrorLevel 130: 41-60meg Hard Disk
ErrorLevel 131: 61-80meg Hard Disk
ErrorLevel 132: 81+ meg Hard Disk
ErrorLevel 255: unknown disk type,
door open,
or other error

NOTE: RamDisks of various sizes may be identified oddly.
For example, a 5 megabyte ram-disk will return ErrorLevel 4.



****************
**** FileFits.exe ************************************************************
****************
FileFits is a utility that reports (in ErrorLevel) on a file's size.
It can be used to determine if a file is to large for a particular
application program before the application is run. It can also be used
to spot empty files, which are sometimes the side-effect of some accident.

usage: FILEFITS file.ext (size)

example: FILEFITS MYFILE.TXT 64000

returns: ErrorLevel = 0 if file size is < or = (size)
ErrorLevel = 1 if file size is > (size)
ErrorLevel = 255 file not found

note: (size) is expressed in bytes, NOT kilobytes.

Most editors won't work with files larger than what will fit in available
memory. Here's a batch file that checks the size of a text file, runs the
editor if possible, or a text file viewer instead. Substitute "EDITOR",
"LISTER", and the trigger file size with names and value appropriate to
what you've got in your system.

Echo Off
if "%1"=="" goto Whoops
FileFits %1 64000
if ErrorLevel 255 goto Whoops
if ErrorLevel 1 goto View
EDITOR %1
goto End
:View
LISTER %1
goto End
:Whoops
Echo !!!ERROR!!!
:End

If you use this example, be sure to substitute the names of the editor and
file viewer you use. The value 64000 should be replaced by a value appropriate
to your system and situation. You may have to experiment to determine this
value.



****************
**** FileSize.exe ********************************************************
****************
FileSize.exe is a utility that reports file size in ErrorLevel.
FileSize can be used by a batch file that displays the rough amount of
time a file will take to send to a modem, or printer. It could also be
used to tell if a file will fit on a small ramdisk, etc.
NOTE: If FileSize returns 0 that does not necessarily mean that the file is
empty! It just means that the file is smaller than 1k. To see if a
file is empty, use FileFits (see above).

Usage: FILESIZE file.ext
Returns: ErrorLevel 0-253: file size in k
ErrorLevel 254: file larger than 253k
ErrorLevel 255: file not found



*************
**** Input.exe ************************************************************
*************
Input.exe is a utility that allows user input in batch programs.
Most user input programs let the user type in a single key, and then
report which key was pressed in ErrorLevel. Input.exe allows the
user to type in an entire line of text, and places this text in an
environment variable. It can be used to get a parameter the user forgot
to enter, or to get a filename, filespec, path or whatever.

NOTE: You MUST read the section of this file called "About Environment
Variables" before using this program.

usage: INPUT envname
envname - The name of the Dos Environment Variable where
you want Input to store what the user types.
This variable must be created and
sized before you can run Input.

example batch file:
Set Test=12345678.123
Echo Please type in a filename.
Input Test
Dir %Test%
Set Test=

Input will return an ErrorLevel of 1 if it can't find the environment variable.

With a little clever redirection it can also put other things in environment
variables. For example, the following portion of a batch file will save the
current directory in an environment variable.

rem Create and size environment variable.
Set OldDir=123456789012345678901234567890

rem CD command with no parameters displays current dir.
rem Redirect into Input.
CD | Input OldDir
CD /Data
.
.
.
rem Later on, directory is restored and environment variable is destroyed.
CD %OldDir%
Set OldDir=



****************
**** Selector.exe ************************************************************
****************
Selector.exe is a point and shoot file picker for batch programs.
It can provide an easy to use, point and shoot menu from which
the user can select a file. The name ONLY (no path) is then placed
in an environment variable. Be SURE to read the section on at the end
of this file called "About Environment Variables" before using Selector.

Usage: SELECTOR envname filespec1 [filespec2...] ["title goes here"]
envname - The name of the environment variable that Selector
will use to store the name of the file selected by
the user. This environment variable must first be
created and sized. Example:
SET TEXTFILE=12345678.123
SELECTOR TEXTFILE *.TXT *.DOC "Text Files"
TYPE %TEXTFILE%
SET TEXTFILE=
The batch program shown above will type the text
file that the user selects. Be sure to get rid of
the environment variable when you are done with it.
filespec - The type of files Selector will display to the user.
For example: *.txt
You can use as many filespecs as you want, just
separate them with spaces.
title - Optional title that Selector will display.
It must be enclosed by quotes ("").

Selector will allow the user to abort by pressing the ESC key.
If this happens, Selector will not modify the environment variable,
and will return an ErrorLevel of 1. This will also happen if no
files matching any of the filespecs given are found.

Selector will clear the screen before and after it does it's thing,
so you don't have to worry about it yourself.

Selector uses whatever colors are on the screen when it starts,
so you can use one of the many available utilities to set colors
the way you like. However, if the foreground color is too bright,
Selector may have trouble highlighting the current file.
That's because all text is already highlighted.



******************************
*** About Environment Variables *********************************************
******************************

The Dos Environment (or Set) is an area of limited size where Dos stores
information in environment variables. Each variable takes the form:
NAME=One or More Words
Here are some examples:
OLDDIR=c:\SprdSht\Data
PHNUM=555-1212
LINES=43
PARA=/d+ /s- /f

Some applications allow you to set parameters using an environment variable
instead of the command line. Dos itself uses three environment variables.
These are COMSPEC, PATH, and PROMPT. You __MUST NOT__ use these names for
your own variables. Comspec is where Dos stores the location of command.com
so it can re-load it when necessary. Path and Prompt are where Dos stores
the search path and current prompt settings.

You can create, change and view your own variables using the Dos Set command.
To view the set of all variables just type SET at the C> prompt. To change
a variable type SET NAME=Whatever. The variable NAME will now be set to
Whatever. IMPORTANT: Do NOT leave a space between the environment
variable name and the "=". For example:
RIGHT: Set Test=Qwerty
WRONG: Set Test =Qwerty
To destroy an environment variable type: Set Name=
Be sure you don't type anything after the "=", not even a space.

The environment is only so big, and if you put a lot of stuff in it, you
may run out of space. If you are using Dos version 3.2 or later, you can
set the size of your environment by putting the line:
SHELL C:\COMMAND.COM /E:512 /P
in your Config.sys file. Be SURE to replace C:\ with the proper path to
Command.com, and replace 512 with whatever size (in bytes) environment you
would like to have.

One odd thing about the environment set is that every Com and Exe program
gets it's own copy of the environment. This way, if a program modifies it's
own copy, the master copy is not changed. The drawback to this approach is
that you can wind up with several copies of the environment.

Since Input and Selector aren't sure which copies to change, they change all
copies of the environment. This can be confusing because it is contrary to
normal practice.

If you use Selector or Input in a batch file that will be run from inside
of an application program, you may find that the environment has shrunk
to a size that just barely large enough to hold the amount of stuff already
in it. To cure this problem, create the environment variable before you run
the application. You might even want to create a generic environment variable
in your AutoExec.bat file, so that you'll always have it ready to go.