Site hosted by Angelfire.com: Build your free website today!
2002-01-01Homepage


MAX

Bat Flying

BAT



Homepage


RAR Backup ARJ Backup ANSI Keys
Cleanup CLI Calc LOG Date,Time
RESCUE MAN Pages PUSHDIR

MAX.BAT is an abreviation for maximum batch file. A batch file that is allowed to become one huge batch file rather than scattering smaller batch files into many directories where they are soon forgotten or accidently erased.

DOS uses a minimum of one cluster to store any file. Cluster size will range from 1024 to 32k depending on the size of the partition. A small 300 byte batch file can occupy as much as 32k of your hard drive. If this was the only reason for MAX it would be only somewhat worthwhile. MAX can be stored in the root directory of your C: drive without garbaging up a directory display the way several dozen small batch files would. It is always in the path and can be called from any drive and any partition. It is not a TSR like DOSKEY and uses no DOS memory but it can automate many repetitive tasks that would require typing long command lines each time without it.

MAX works with any version of DOS and is so simple that it's usefulness is not immediately obvious. Use it for awhile and you will wonder why it wasn't a part of DOS from the beginning.

You can type this in yourself, use CTRLALT from within a DOS text-only browser, or cut-n-paste from within a W3.x browser but the easiest way would be to download the examples and then modify one of those. I have always been annoyed when example code was nowhere to be found for downloading.

In it's simplest and shortest form MAX would be:

( EXAMPLE1.BAT )

@echo off
cls
:
if "%1"=="" goto Syntax_Max
set cmd=%1
shift
goto @%cmd%
goto Syntax_Max
:
:@rem ----------- lists all MAX commands
:
:@cmds
find ":@" c:\max.bat | more
goto done
:
:@rem ----------- backup to 1.44meg diskettes
:
:@rarback
rar a -srm5 -vd -w%temp% -v1440 a:\bkup.001 c:\*.*
:
goto done
:
:rem -----------
:
:Syntax_Max
cls
echo Syntax Error, you entered:
echo max %cmd% %1 %2 %3 %4 %5 %6 %7 %8 %9
:
goto done
:
:rem -----------
:@
:Done
set cmd=

Up Arrow

This small example MAX.BAT has only two commands max cmds and max rarback. To use the rarback command you would put a blank formatted 1.44meg diskette in your A: drive and type:

max rarback

This assumes that you have RAR stored somewhere in your path on your hard drive and that you have set a %TEMP% variable in your environment pointing to a directory that you use for temporary files ( do this in AUTOEXEC.BAT with the set command). RAR will use the hard drive to store each volume at the specified size of your diskettes, in this case 1.44 meg, of the archive at the %TEMP% directory until it is finished. As each is created it is copied to the diskette which is much faster on legacy hardware than writing directly to the floppy drive. If you do not have RAR on your system you should, it's the most reliable archiver for DOS that I have found because of it's built-in error recovery if you use the `create solid archives' switch. PKzip is much faster but never seems able to repair damaged ZIP files.

RAR would then make volumes that will fit on 1.44m diskettes and archive your entire C: drive to disks, waiting for you to swap disks as each one is filled with one volume and erasing each one before attempting to fill it with each volume. There are better options for making backups but this is one option and the solid archives that RAR uses are more dependable than other archive types for long term storage error recovery if a volume is corrupted by aging on the diskette or some other catastrophic event.

If you have a ZIPdrive with 100meg or 250meg removable disks or a second hard drive to copy the archives to then set RAR to create volumes of that size. This is flexible.

No need to memorize RAR switch commands or forget the most important ones (such as the `solid' switch) and find out that your RAR files won't repair themselves when one is damaged. Any arrangement of RAR switches that you use often can be given a command name and added to MAX. You can have one set for quick temporary archives and another more complex configuration for long term storage.

Any batch file that you already keep on your system can be put between the REM lines and given a command name, or you can use the name of the batch file as the command name in MAX. No need to re-learn all your batch file names. The only change is to type MAX at the command line, then the same batch file name and any switches that you have been using in the past. Easy enough?

One more example. Download the examples and rename EXAMPLE2.BAT to MAX.BAT. To add ARJ for making voumes that each fit on 1.44m diskettes (but with a less robust error recovery than RAR) you would edit MAX with a text editor and add these lines:

( EXAMPLE2.BAT )

:@rem ----------- backup to 1.44meg diskettes
:
:@arjback
arj a -rjm1i2jt -w%TMP% -v1440 a:\bkp.001 c:\*.*
:
goto done
:

any place after the line:

goto Syntax_Max

New commands do not have to be in alphabetical order within MAX but those that you want to execute repeatedly (MAX can call itself recursively) will be faster if put near the top of MAX. Once these lines are added you have two backup commands. One command is "max rarback" and the other command is "max arjback".

If you forget the commands that you have added to MAX just type:

max cmds

at the command line and press ENTER. MAX will search itself using the DOS utility FIND.EXE and display all of the commands and the @REM comments describing what they do. That is the reason why they all start with "@" as the first character. When MAX gets larger the DOS command "more" will pause the display for you using the "|" pipe command.

MAX uses the "shift" command to move all of your command line switches back one so that it can use the first word after "max" to locate your routine within MAX. This is not a problem because DOS allows nine variables after a command to be passed to a batch file. With this shift backwards MAX allows only eight. I have never needed all eight so this should not become a problem for anyone using MAX.

You may be wondering about all the ":" that start most lines of MAX. The DOS command interpreter will take the time to read every character looking for a match of any line that begins with REM but it thinks all lines that start with a ":" are labels and only looks for a matching label (one word). The first character that is not a match stops the reading of that line. In short, the batch file executes faster using a colon to start empty lines or as REM lines and the extra spacing makes reading and editing MAX easier. Try using these colons within a large batch file you have used before and you will see the difference in execution speed.

Up Arrow


Want to program your function keys to actually do something and not just take up space on the keyboard? Add this line:

DEVICE=ANSI.SYS

to your CONFIG.SYS file and then add this to MAX:

( EXAMPLE3.BAT ) :rem -----------
:
:@Ansikey
if not "%9"=="" goto Error
if "%1"=="" goto Error
goto %1
:F1
ansi ~[0;59;"%2 %3 %4 %5 %6 %7 %8"p
goto done
:F2
ansi ~[0;60;"%2 %3 %4 %5 %6 %7 %8"p
goto done
:F3
ansi ~[0;61;"%2 %3 %4 %5 %6 %7 %8"p
goto done
:F4
ansi ~[0;62;"%2 %3 %4 %5 %6 %7 %8"p
goto done
:F5
ansi ~[0;63;"%2 %3 %4 %5 %6 %7 %8"p
goto done
:F6
ansi ~[0;64;"%2 %3 %4 %5 %6 %7 %8";13p
goto done
:F7
ansi ~[0;65;"%2 %3 %4 %5 %6 %7 %8";13p
goto done
:F8
ansi ~[0;66;"%2 %3 %4 %5 %6 %7 %8";13p
goto done
:F9
ansi ~[0;67;"%2 %3 %4 %5 %6 %7 %8";13p
goto done
:F10
ansi ~[0;68;"%2 %3 %4 %5 %6 %7 %8";13p
goto done
:
: Std - fn key defines : 59 - 68 ( F1 - F10 )
:
: Shift - fn key defines : 84 - 93 ( F11 - F20 )
:
: Ctrl - fn key defines : 94 - 103 ( F21 - F30 )
:
: Alt - fn key defines : 104 - 113 ( F31 - F40 )
:
:Error
echo .
echo .
echo Syntax: ANSIKEY F# {text, up to 8 words}
echo .
echo .
goto done
:

This addition to MAX requires a small COM utility ANSI.COM that you must put in your "C:\" directory or this code will not function. This 28 byte utility file is included in the MAX archive that you may download from this server. The function keys can be programmed using the PROMPT variable but it's slow and a bit of a kludge (sloppy coding) and ANSI.COM is useful for other batch file routines when you don't want the carriage return and line feed that the batch file command ECHO adds to each line it displays.

You can now program the F1-F10 keys to retype any text you want them to without having to remember the ansi codes that program these keys. Just type:

max ansikey F10 pkzip -u c:\dfilz.zip c:\dos\*.*

Now when you press the F10 key all of the files in the C:\DOS directory will be added using the update function of Pkzip to the DFILZ.ZIP archive. This is just an example, you can program any command string you can type into just one keypress.

MAX is so easy to add commands to that programming function keys is seldom required but for a quick set of commands you intend to repeat many times this is one way to do that if you already have an ANSI.SYS driver loaded by your CONFIG.SYS file. I realize that newer DOS versions can use DOSKEY but that uses additional memory and older versions of DOS do not have that utility program. Older PC's and XT's can't always spare the memory for other similar utilities like CED, PCED, NDOSEDIT, or 4DOS.

Up Arrow

AUTOMATED CLEANUP / DEFRAG   Backup Your Hard Drive

NOTE: This next batch code example is very useful but not easilly made into a generic version that will work on every system. It needs customizing to suit your setup and what you want it to do. I will include it with the other example code but do not execute this MAX command until you are certain it only does what you want it to do.

Hard drives and even diskettes become fragmented and we must use a third party DEFRAG program to put these pieces back in one contiguous area. The problem is we often do this before removing temporary files and then when we delete these temporary files at some later time we create an opportunity for DOS to begin scattering parts of the next files we write to the hard drive or diskette by re-using all these little empty spaces from our deleted temporary files.

The Solution, for me, was to automate this process so that I don't forget to remove temporary files and to use either CHKDSK or SCANDISK before attempting to defragment the hard drive ( always a potential disaster if things go badly).

Deleting temporary files that remain from our use of the ctrl-alt-del escape keys or worse, having to turn the machine off / on to reboot, can be risky. If they have crossed clusters deleting them can take out parts of good files. To attempt to avoid this mistake we do CHKDSK or SCANDSK first on all partitions with the MAX command below:

( EXAMPLE4.BAT - part A )

:rem ----------- repair any crossed clusters
:
:@check
:
for %%i in (c: d: e: f:) do chkdsk %%i /f
:
goto done
:

The drive letters ( partitions ) will need to be edited to suit what you have on your system. For newer DOS versions you would replace CHKDSK with SCANDSK and the appropriate switches that you would normally want to use. Typing "max check" after a crash would be a good idea if you don't want to spend time reformatting your hard drive and restoring all of your files using your backups. You DO keep backups, right?

The removal of temporary files using UFIND is next and should be all one line but it won't fit on a smaller 640x480 webpage display as one line so this will require editing to add with cut-n-paste. This next command does the deleting of the temporary files - finally!

( EXAMPLE4.BAT - part B )

:@rem ----------- delete temp files
:
:@clean
ufind %1 -name *.~mp *.gid *.fts *.chk y*.---
*.$$$ *.*$ ~*.* *.~* *.??_ *.??~ *.^* *.syd
*.prv *.bak ip-up.* -rm
:
goto done
:

Remember UFIND should be all one line in your batch file. This scans the entire drive, not just one directory. If files with these extensions and all wildcard variables of these extensions exist anywhere on the specified drive they will be erased.

The "*.??_" will remove W3.x compressed files from your hard drive. Many keep them available on their hard drive rather than use the install diskettes and do not want them deleted. If you are one of those people then definitely remove the "*.??_" from this command. Examine this line carefully for file types that you do not want to delete. I can only say that with DOS and W3.x here no files that I need are deleted using this routine in MAX.

The utility UFIND can be downloaded separately from this server and is included with the MAX archive also available here. UFIND is an older DOS utility and will not work properly with every version of DOS. I do not have every version of DOS and cannot, therefore, be more specific. I suspect that it will stop functioning with hard drive partitions of 2gig and/or a total drive size in the range of 8 gig? Untested but be forewarned.

There are other utilities that will scan entire drives and delete specified file types. I have used UFIND for this but nothing is stopping anyone who has a preference for any other similar utility from substituting their favorite. Be certain that you understand the syntax for any other utility you use to replace UFIND! DETLTREE is not the same thing and might delete every directory and every file on every drive. Be careful with this. If this seems to be overkill to you, an optional format would be to specify directories this way:

:@rem ----------- delete temp files
:
:@clean
if exist %temp%\*.* delete %temp%\*.$$$
if exist %temp%\*.* delete %temp%\*.bak
if exist %temp%\*.* delete %temp%\*.prv
... etc. etc. etc.

The `if exist' is used to avoid file not found messages on your screen when this is executing and delete can't find the file you want to delete. Older versions of DOS would use "del" to replace "delete". This would give you more control to leave certain file types while removing others and only in certain directories. In this example any directory designated as your `temp' directory in your environment using the `set temp={drv}{dir}' command (usually done in autoexec.bat). This would take longer to setup properly but you can surgically remove only certain files and once it's working it's working forever!

Now we can hope to safely remove any temporary files left behind on our hard drive by a multitude of programs that think they own all of your available space! This is done by stepping through all of your drive letters and calling `clean' using:

( EXAMPLE4.BAT - part C )

:@rem ----------- loop for 'clean'
:
:@cleanall
:
echo Next op will delete any
echo Win setup files ending in "*.??_"
pause
for %%i in (c: d: e: f:) do call max clean %%i
:
:@free
for %%i in (c: d: e: f:) do free %%i
:
goto done
:

This has two MAX commands in it, max cleanall and max free . I use max free to keep track of how much space I have on each partition and after removing the temporary files it's interesting to see how much space you have reclaimed. The FREE.COM utility will not work on newer large drives but is included for those with older versions of DOS that did not have this function. With "cleanall" you see that MAX can call itself ( recursion ) which allows us to break up complex tasks or to build complex tasks from smaller ones. I added the "pause" just in case I was in the middle of an install and did not want to lose the compressed files. Press CTRL-BREAK at this point if you are not certain that deleting these files will be OK.

Now we combine these MAX commands into one routine by calling each one from within MAX.

( EXAMPLE4.BAT - part D )

:rem ----------- remove all temp files
:
:@cleanup
:
call max check
call max cleanall
:
goto done
:

DOS versions prior to v3.3 MSDOS did not have the CALL command and should use "command /c" to replace both instances of CALL. The "@echo off" should also be replaced for older versions of DOS with "echo off". Anyone with a version of DOS older than v2.11 cannot read subdirectories and should probably upgrade their DOS to one of the newer free versions such as DRDOS or FreeDOS?

The command "max cleanup" will check for crossed clusters and then remove all temporary files from all partitions on your hard drive. You can now safely and effectively defragment your hard drive. I will leave the automation of the defrag program as an exercise for each user. There are many defrag programs and I would probably pick the one you do not have. If your older DOS version does not have a defrag program you can try one of these . I used DOG for many years with v3.1 and v3.3 MSDOS.

I used the PcTools COMPRESS program after trying several others because it continuously rewrites to the FAT so that interruptions and power failures won't take out my entire partition. I also used to finish with MIRROR.COM to keep a copy of the FAT for emergencies. The defrag included with MSDOS v6.22 is written to function in a similar fashion and I am confident that it is a good choice to defrag my drives with. I have switched to the MSDOS v6.22 defrag now.

Up Arrow

A useful addition to MAX is a one line batch file that does command line math for you. Creating one line batch files was a popular pastime years ago and I found this while reading echomail. It requires GWBASIC to do it's work. QUICKBASIC replaced the interpreted GWBASIC at some point in DOS but will not substitute for this batch file, sorry.

The ECHO line should be all one line but won't fit on this webpage. Recombine the two lines back into one line before testing this on your system.

(CALC.BAT)

:@rem ----------- CLI Math
:
:@Calc
:
ECHO ? CHR$(61); %1 %2 %3 %4 %5 %6
%7 %8 %9 : SYSTEM :|GWBASIC|FIND "="
:
goto done
:

This follows the BASIC programming language math syntax using the asterisk as the multiplication sign and following algebraic entry order for precendence of paranthesis as most pocket calculators do. Try this command line. Your answer should be 48.

max calc 2*(3*8)

Another one line batch file that depends on GWBASIC to function is LOG. Logs the date and time into LOG.DAT for you. I seldom need to keep track of my own logins but if nothing else it's another puzzle as to how it all works? HINT : The "?" doubles as the word "PRINT" in interpreted BASIC.

(LOG.BAT)

:rem -----------
:
:@Log
:
ECHO ? DATE$, TIME$ : SYSTEM |
GWBASIC|FIND/V "?" >C:\LOG.DAT
:
goto done
:

The ECHO line should be recombined into one line, no space before the GWBASIC. Type:

max log

and the date and time are logged for you.

Collecting small COM file utilities can make using DOS more enjoyable but I used to have a habit of erasing the DOC file before I had time to learn all the command line switches. Bad habit. The solution was to rename each DOC file, after editing it down to size, to the name of the COM utility plus HLP as the extension and ZIP them into one large HELPDOX.ZIP archive. The following batch code will retrieve them for you any time you need to lookup a switch command. Change the drive and directory to point to where you have put your archive.

(HELPDOX.BAT)

:@rem ----------- DOC's
:
:@dox
:
pkunzip -c f:\util\helpdox %1*.hlp| list /s
:
goto done
:

This makes use of Pkzip for it's speed and uses V.Buerg's LIST.COM program to search, scroll backwards and forwards, etc. while viewing the documentation. If you do not want to download LIST.COM (not included in the MAX downloadable archive) replace "list /s" with "more". To use this command type:

max dox newutil

The file "newutil.hlp" will be displayed on your screen in a flash. Something like the *NIX manpages but compressed into an archive. Keeping all these DOC files is less painful if they are all in one place and compressed.

Up Arrow

With only 640k of memory each TSR is a loss of precious memory. When using Windows 3.x in a dosbox loading a TSR can trash Windows and cause damage to partially written files. TSR's can be a pain.

PUSHDIR.COM and POPDIR.COM will allow a batch file to move to another partition and back again but PUSHDIR.COM is a TSR. Using it sacrifices memory or even brings down the OS when it loads. The solution is to use MAX instead.

(PUSHDIR.BAT)

:@rem ----------- PUSHDIR
:
:@pushdir
:
@ansi cdd >%temp%\popdir.bat
@cd >%temp%\popdir.bat
:
goto done
:

The COM utility ANSI.COM is included in the MAX archive but you will need to have a CDD.EXE that can move across partitions using drv\directory commands or this will not work for you when you need to move to a different partition and return to the one you started at. It will work within one partition without CDD.

When you want to save the directory where you are "max pushdir" will create the batch file POPDIR.BAT in the directory specified in your %TEMP% variable of your environment. To return put "CALL %TEMP%\POPDIR" in your batch file. (legacy DOS users will need to use "COMMAND /C %TEMP%\POPDIR")

I hope this has given you some idea what MAX.BAT is for. Looking for those little batch files scattered around can be frustrating and a time-waster. MAX is a time-saver.

While discussing MAX and batch files it is worth mentioning that BATCHMAN.COM from PcMagazine, a 5400 byte COM file, contains 48 commands that will make writing batch files much easier than it is without batchman. You will be impressed if you've never used batchman before.

Up Arrow

RESCUE.BAT - Installing and uninstalling new applications for Windows 3.x can be problematic. Installers don't tell you what they are doing and even though WinZip will wait to uninstall files, if you tell it to, WinZip can't put back DLL's that were overwritten with older ones nor will it replace your original SYSTEM.INI or WIN.INI files for you. InControl v3.0 will create a listing of altered files but won't save the originals either. My solution was to write RESCUE.BAT and save those files most often disturbed when a new application is installed.

This batch file uses a subdirectory RESCUE added to the WINDOWS directory by the "MD RESCUE" command while in the WINDOWS directory and uses RAR.EXE to create the archives.

( RESCUE.BAT )

@echo off
:
if not %1/==/ goto filechk
echo .
echo .
echo syntax: rescue ## (number required)
echo .
echo .
dir c:\windows\rescue\rescue*.rar
goto fini
:
:filechk
:
if not exist \windows\rescue\rescue%1.rar goto isok
echo .
echo .
echo The file rescue%1.rar already exists
echo .
echo .
rar p c:\windows\rescue\rescue*.rar *.diz | more
goto fini
:
:isok
:
c:
cd c:\windows
if exist \windows\rescue\rescue%1.rar goto fini
echo Rescue to what point?
echo .
echo press ctrl-Z when finished
copy con rescue.diz
:
: This line should be all one line but
: webpages require that I wrap it here
: for display on a webpage.
:
rar a -col -sm5 -rr8 -wj:\
\windows\rescue\rescue%1.rar *.dll *.grp
reg.dat rescue.diz system\*.drv
system\*.386 *.ini
:
del rescue*.diz
:
:fini

NOTE: Those with early versions of DOS should use "echo off" without the @ sign. I have used "-wj:\" because my J: partition is for temporary files. Another way to code this might be "-w%TEMP%" to use the temporary directory selected in AUTOEXEC.BAT with the "set temp=" command.

RESCUE will check the number you choose so that an earlier save doesn't get overwritten by your next one. I keep three or more just in case I find a troublesome application a week or so after I think it's OK. It happens.
If the number is not in use RESCUE creates a DIZ file to add to the archive. DIZ files are description files. Try to type in useful information. I use the filename of the new application I am installing.
If the number is already in use RESCUE will display the DIZ files in all existing rescue archives using MORE to pause the display. V.Buerg's LIST.COM can be used as "LIST /S" to allow scrolling backwards and forwards to read these. Unfortunately RAR likes to brag and there is a great deal of garbage in this display.

If RESCUE is used before each install in addition to whatever other uninstaller you normally use you should be able to return your system to where it was by using the UNRESCUE.BAT file after removing the new application and any new directories it created.

( UNRESCUE.BAT )

@echo off
:
if not %1/==/ goto filechk
echo .
echo .
echo syntax: unrescue ## (number required)
echo .
echo .
dir c:\windows\rescue\rescue*.rar
goto fini
:
:filechk
:
if exist \windows\rescue\rescue%1.rar goto isok
:test2
echo .
echo .
echo The file rescue%1.rar does NOT exist
echo .
echo .
rar p c:\windows\rescue\rescue*.rar *.diz | more
goto fini
:
:isok
:
c:
cd c:\windows
if not exist \windows\rescue\rescue%1.rar goto test2
:
echo UN-rescue is replacing files ...
:
: This line should be all one line but
: webpages require that I wrap it here
: for display on a webpage.
:
rar x -o+ -col \windows\rescue\rescue%1.rar
*.dll *.grp reg.dat rescue.diz system\*.drv
system\*.386 *.ini
del rescue*.diz
:
:fini

Both RESCUE and UNRESCUE are available for downloading but you will need to edit these to adapt them to your setup if any of the drive letters or directory names are different on your system.

Other useful DOS batch files distributed by the BFDS FDN (Batch File Distribution System at the FIDO Distribution Network) can be found at:
HTTP access or FTP access.

Enjoy!

Up Arrow
Valid HTML 4.01!
©Charles Angelich 2001 Server a bit slow? Try a  MIRROR SITE