home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol11n19.zip / DELBAK.BAT < prev    next >
DOS Batch File  |  1992-02-22  |  2KB  |  60 lines

  1. @ECHO OFF
  2. IF '%1'=='' GOTO Syntax
  3. SET driv=
  4. :: Be sure the command line parameter is a single letter
  5. :: Using / in front of an item in the FOR list splits the
  6. :: first letter of that item from the rest.  Only if the
  7. :: parameter was a single letter to start with will the
  8. :: driv variable have the same value as the parameter.
  9. FOR %%v IN (/%1) DO SET driv=%%v
  10. IF NOT '%driv%'=='%1' GOTO Syntax
  11. :: Get the list of BAK files on the requested drive
  12. DIR %1:\*.BAK /B/S/L > BAKLIST1.$$$
  13. :: Make sure the list is not empty
  14. COPY BAKLIST1.$$$ BAKLIST2.$$$ > NUL
  15. IF EXIST BAKLIST2.$$$ GOTO HaveFiles
  16. ECHO There are no BAK files on drive %1:!
  17. DEL BAKLIST1.$$$
  18. GOTO End
  19. :HaveFiles
  20. :: Create the DELCMD.$$$ file
  21. REM > TEMPDEL.BAT
  22. ECHO NDELCMD.$$$> MAKEDEL.SCR
  23. ECHO F 100 L 9 " ">> MAKEDEL.SCR
  24. ECHO E 100 "DEL">> MAKEDEL.SCR
  25. ECHO RCX>> MAKEDEL.SCR
  26. ECHO 9>> MAKEDEL.SCR
  27. ECHO W>> MAKEDEL.SCR
  28. ECHO Q>> MAKEDEL.SCR
  29. DEBUG < MAKEDEL.SCR > NUL
  30. DEL MAKEDEL.SCR
  31. :: Build a batch file containing each of the filenames
  32. :: with "DEL " in front of it.
  33. :loop
  34. :: Prefix the first line of the list with "DEL "
  35. COPY DELCMD.$$$ + BAKLIST1.$$$ BAKLIST2.$$$ > NUL
  36. :: Use FIND to extract that first line into a new file
  37. TYPE BAKLIST2.$$$ | FIND "DEL " > BAKLIST3.$$$
  38. :: Show the new file
  39. TYPE BAKLIST3.$$$
  40. :: Append the DEL command line to TEMPDEL.BAT
  41. COPY TEMPDEL.BAT + BAKLIST3.$$$ > NUL
  42. DEL BAKLIST3.$$$
  43. :: Copy all lines *except* the first back to the original list
  44. TYPE BAKLIST2.$$$ | FIND /V "DEL " > BAKLIST1.$$$
  45. DEL BAKLIST2.$$$ > NUL
  46. :: Check whether the original list is empty
  47. COPY BAKLIST1.$$$ BAKLIST2.$$$ > NUL
  48. IF EXIST BAKLIST2.$$$ GOTO loop
  49. :: Reach this point when the list is empty
  50. DEL BAKLIST1.$$$
  51. DEL DELCMD.$$$
  52. ECHO Press Ctrl-Break if you do *NOT* want to delete BAK files, or
  53. PAUSE
  54. CALL TEMPDEL.BAT
  55. DEL TEMPDEL.BAT
  56. GOTO End
  57. :Syntax
  58. ECHO Syntax: "DELBAK d", where d is a lone drive letter
  59. :End
  60.