Ndos/4Dos batch file utils

You can download the following code samples in zipped form as
ndosutil.zip.


The following are the details for the three files included below, and in the zipfile. Note that these are not necessarily the only or even the best ways to write these batch files. In fact, they may not even work properly on your system. With this in mind, I'd really appreciate anyone telling me how any of them could be improved.

VAL.BTM        60 15/04/95    1:09
Evaluates simple mathematical expressions. Check the section on perl for a more powerful version. Basically, just a command-line call to the %@eval[] function.

!!.BTM       3364 15/01/96   15:57
Acts (usually) like the '!!' shell command, duplicating the last command. Useful only for unix fanatics who can't get used to hitting the up arrow (try bash?), or for coding tips on Ndos programming.

DRIVES.BTM   1358 15/01/96   15:57
Gives as much information about all connected drives as can be obtained from batch commands. Tells you whether they are local, removable, etc (Though CD-ROMs have rather unexected values here), how much space is available, etc.


DRIVES.BTM

@REM A simple command line calculator. @echo %@eval[%&]

!!.BTM

@echo off :: A very rough-and-ready version of the Unix !! function. :: Does not allow changes to arguments, but will allow extra arguments. :: Uses the variable CMDLINE to store the command in. :: NOTE: The ::-style comment should never be used within nested commands. :: Create a name for the temporary file. :namefile if not "%temp"="" ( set file=%@unique[%temp] if not "%file"="" goto initialise ) if not "%ndostemp"="" ( set file=%@unique[%ndostemp] if not "%file"="" goto initialise ) if not "%tmp"="" ( set file=%@unique[%tmp] if not "%file"="" goto initialise ) set file=%@unique[.] if "%file"="" goto nofile goto initialise :: Do other initialisation. :initialise history > %file if not exist %file goto nofile set count=1 goto loop :: The main loop. :loop :: Number of lines from beginning of file. set line=%@eval[%@lines[%file]-%count] :: Check for end of command history. if %line LT 0 goto nocmds :: Read command on current line. set cmdline=%@line[%file, %line] >& NUL unset line >& NUL :: Check for environment space. if "%cmdline"=="" goto noenv :: See if command was '!!'. If so, note arguments & do next command. if "%@substr[%cmdline, 0, 2]"=="!!" ( REM Copy arguments, removing trailing space. set n=%@eval[%@len[%@substr[%cmdline, 3]]-1] set moreargs=%@substr[%cmdline, 3, n] %moreargs unset n REM Point to next command in list & loop. set count=%@eval[%count+1] goto loop ) :: Might not get the chance to clean up if command messes up. gosub cleanup :: Make sure the spacing is OK, then output. if "%moreargs"=="" ( echo %cmdline %& call %cmdline %& goto end ) echo %cmdline %moreargs %& call %cmdline %moreargs %& goto end :: Error handling routines. :nocmds echo. echo Out of history space in !!. The original command has been lost. echo You may wish to allocate more history memory in the ndos.ini file. goto FindNdosIni :noenv echo. echo Out of environment space in !!, so unable to find the original echo command reffered to. echo You may wish to allocate more environment space in the ndos.ini file. goto FindNdosIni :FindNdosIni if not "%@search[ndos.ini]"=="" ( echo. echo An ndos.ini file which may be suitable has been located at: echo %@search[ndos.ini] ) echo. echo You may preffer to type the command in again, or use the up arrow. gosub cleanup goto end :nofile echo. echo Fatal error in creating temporary file. echo. echo Before using the !! utility, you must set the environment variable echo TEMP to point to a drive you have write permission on, with at least echo a few kilobytes free, and make sure you have some environment space echo free as well. echo. echo You can do this in the %_boot:\autoexec.bat file. echo. echo You may preffer to type the command in again, or use the up arrow. gosub cleanup goto end :cleanup :: unset everything bar cmdline. del %file >& NUL unset file >& NUL unset moreargs >& NUL unset count >& NUL return :end

DRIVES.BTM

@echo off REM A program to tell you which drives you have and what they are. REM See also which.btm. cls rem This nasty hack is for getting MORE to work on the program. rem More can be bypassed by using the -p flag. rem if "%1"=="" ( call %0 -P | more ^ goto end ) rem if "%1"=="-P" goto begin rem if "%1"=="/P" goto begin rem goto help :begin cls echo %_time, %_dow, %_date. echo Boot disk is %_boot. Last disk is %_lastdisk. echo Currently in %_cwds. echo. set DRV=A :drvtest if "%@upper[%DRV]" GT "%_lastdisk" goto :end if "%@ready[%DRV:]"="1" goto ready echo Drive %DRV: is NOT ready. set DRV=%@char[%@eval[%@ascii[%DRV]+1]] echo. goto drvtest :ready echo Drive %DRV: (%@label[%drv%:]) is ready. echo Total space: %@disktotal[%drv%:,b] bytes (%@disktotal[%drv%:,K]k). echo Used space : %@diskused[%drv%:,b] bytes (%@diskused[%drv%:,K]k). echo Free space : %@diskfree[%drv%:,b] bytes (%@diskfree[%drv%:,K]k). echos Drive is if %@removable[%drv%:]==1 echos removable and if %@remote[%drv%:]==0 echo local. if %@remote[%drv%:]==1 echo remote. set DRV=%@char[%@eval[%@ascii[%DRV]+1]] echo. goto drvtest :help echo This program is intended to display all the drive information. echo Syntax: "%0 [-p]" echo -p disables paging :end unset DRV >& NUL
return to index