home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS - Coast to Coast
/
simteldosarchivecoasttocoast.iso
/
pcmag
/
vol11n19.zip
/
DELBAK.BAT
< prev
next >
Wrap
DOS Batch File
|
1992-02-22
|
2KB
|
60 lines
@ECHO OFF
IF '%1'=='' GOTO Syntax
SET driv=
:: Be sure the command line parameter is a single letter
:: Using / in front of an item in the FOR list splits the
:: first letter of that item from the rest. Only if the
:: parameter was a single letter to start with will the
:: driv variable have the same value as the parameter.
FOR %%v IN (/%1) DO SET driv=%%v
IF NOT '%driv%'=='%1' GOTO Syntax
:: Get the list of BAK files on the requested drive
DIR %1:\*.BAK /B/S/L > BAKLIST1.$$$
:: Make sure the list is not empty
COPY BAKLIST1.$$$ BAKLIST2.$$$ > NUL
IF EXIST BAKLIST2.$$$ GOTO HaveFiles
ECHO There are no BAK files on drive %1:!
DEL BAKLIST1.$$$
GOTO End
:HaveFiles
:: Create the DELCMD.$$$ file
REM > TEMPDEL.BAT
ECHO NDELCMD.$$$> MAKEDEL.SCR
ECHO F 100 L 9 " ">> MAKEDEL.SCR
ECHO E 100 "DEL">> MAKEDEL.SCR
ECHO RCX>> MAKEDEL.SCR
ECHO 9>> MAKEDEL.SCR
ECHO W>> MAKEDEL.SCR
ECHO Q>> MAKEDEL.SCR
DEBUG < MAKEDEL.SCR > NUL
DEL MAKEDEL.SCR
:: Build a batch file containing each of the filenames
:: with "DEL " in front of it.
:loop
:: Prefix the first line of the list with "DEL "
COPY DELCMD.$$$ + BAKLIST1.$$$ BAKLIST2.$$$ > NUL
:: Use FIND to extract that first line into a new file
TYPE BAKLIST2.$$$ | FIND "DEL " > BAKLIST3.$$$
:: Show the new file
TYPE BAKLIST3.$$$
:: Append the DEL command line to TEMPDEL.BAT
COPY TEMPDEL.BAT + BAKLIST3.$$$ > NUL
DEL BAKLIST3.$$$
:: Copy all lines *except* the first back to the original list
TYPE BAKLIST2.$$$ | FIND /V "DEL " > BAKLIST1.$$$
DEL BAKLIST2.$$$ > NUL
:: Check whether the original list is empty
COPY BAKLIST1.$$$ BAKLIST2.$$$ > NUL
IF EXIST BAKLIST2.$$$ GOTO loop
:: Reach this point when the list is empty
DEL BAKLIST1.$$$
DEL DELCMD.$$$
ECHO Press Ctrl-Break if you do *NOT* want to delete BAK files, or
PAUSE
CALL TEMPDEL.BAT
DEL TEMPDEL.BAT
GOTO End
:Syntax
ECHO Syntax: "DELBAK d", where d is a lone drive letter
:End