
WINNER OF DOSWORLD MAY 97 MAGAZINE'S "BEST OF THE BATCH" ----- PLUGB.BAT 

     Have you ever downloaded a large number of files of different sizes to
a directory and then tried to jockey them onto diskettes (some empty, some part
full) while trying to put the most files you could on each? No use straining
your brain trying to figure it out when you have a computer that can do it in a
breeze. You just need the proper program to help you, and here it is.

     I call the program "plugb" because I always put them on drive B: onto
diskettes. But for that matter you can use it for any drive by changing B: to
whatever: And, for that matter, the size of the diskettes doesn't matter, and
the type of format size doesn't either. For instance, the diskette can be
regular Dos format for that drive or can be an extended DMF format or even
an extended FDFormat (any number of tracks, any number of sectors per track).
"Plugb" consists of a couple of batch files and a couple of utility .com files
that you can easily get from earlier issues of DOSWORLD magazine. "Plugb" is 
the main working program and calls "willfill.bat".

     The theory is simple. Make a list of the filenames in order of size:
largest first, smallest last. Check each file against the unused space on the
diskette, copy what fits and skip what doesn't. Also keep track of what has
been copied. (here it is done by moving the file out of the working directory
to the subdirectory). The program runs until the diskette runs out of space and
requests another, (and loops), or until all files are copied.

     Here's how it works. In plugb.bat, the second line checks for the presence
of subdirectory BB1$ to whatever directory you (and the files) are in. If it
doesn't exist, it is created. If it already exists, it leaves it alone. (This
is important. You will see why later.) Next, it takes a directory of only the
filenames from largest to smallest and places the list in the file wil.lis in
the main directory. (I use the main directory only because everyone has one,
and it will only be a temporary file anyway.) Next the file with the list is
turned into a batch file wil$.bat by using prefix to add "call willfill" to
the beginning of each line. Then wil$.bat is called so each file in turn is
tested to see if it "willfit" the remaining space on each diskette you use.
Next wil.lis and wil$.bat are deleted. (housekeeping!!) After that, there is a
test to see if files remain in the present directory. If empty, the program
jumps to the last subroutine. If files still exist a new diskette is asked
for and pauses for the diskette to be changed, then loops and makes a new list
and each remaining file is checked to see if it "willfit".

     Now it is essential for the program to keep track of what files have been
written to diskette and which have not. If you will notice in willfill.bat
after each file has been checked and okayed by willfit.com the file is copied
to the diskette B: and made readonly for protection, then right after, the
file in the directory is moved to the newly formed subdirectory BB1$. Every 
time a file in the directory is written to diskette, it disappears from the
directory and therefore the next directory list. This loops until all the files
are gone. The ctty nul and ctty con commands that surround the move command
are there to keep the screen less cluttered and avoid confusion. When the
working file directory is empty, the files are moved back from the subdirectory
BB1$ and BB1$ is removed.

     Consider now that you can stick in any formatted diskette with other
files on it or not. The display will show which files are copied to diskette
or a "Sorry, won't fit" message shows the file is too large. The dir/-p/a B:
shows an update of what ends up on the diskette.

     Earlier I made mention of the test for subdirectory BB1$. This makes
possible a control-break at the pause for diskette. That makes possible
a break in the action, in case there is a "Sorry, won't fit" file that is
too large for even an empty diskette. (or some other unforeseen problem to
be resolved). After this break in the action, the program allows you to restart
from the point you were at just by typing "plugb" again.

     Although the program sounds complicated, it in fact works very easily
even the first time you use it. Plugb can be used from any hard drive letter
and in any directory as long as you are in the working directory where the pile
of files are. The subdirectory BB1$ was an attempt to come up with a unique name
that wouldn't exist usually. The subdirectory name can be altered if you alter
in all instances of its mention in both plugb and willfill. Also drive B: can
be A:  But you must alter all references to it in both plugb and willfill. The
program is easily customized for your needs. The message ... needs new diskette
can be reworded and the echo  [1;36m color isn't necessary, although I think
it shows up better on the display. The programs plugb.bat, willfill.bat,
prefix.com, and willfit.com must be present in a directory in your "path"
statement. They were designed for Dos 6.+ but may work with earlier versions
with a little bit of alteration.

     Now you won't have to worry about what diskette will hold what programs
any more. Just take each partly filled diskette and try plugb until all the
files are stored. Put your feet up and relax. Let the computer do the work!

     P.S. make sure you put all the "." s in the program because they are
the reason for allowing the program to work in any directory without needing
actual names.
                           GEORGE SHADOFF
                           Mississauga, Ontario, Canada

email: rn.8608@rose.com

