home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1992 / 14 / pd.bat < prev    next >
DOS Batch File  |  1992-01-16  |  2KB  |  58 lines

  1. @echo off
  2. if %1/==/ goto Syntax
  3. if %z%/==/ goto Syntax
  4. ::
  5. REM Create a file containing the name of this batch
  6. REM file followed by the directory on which it was
  7. REM invoked, a backslash, and a Ctrl-Z character.
  8. ::
  9. echo %0 %1\%z% >%1\ch.$$$
  10. ::
  11. REM Create a file listing the subdirectories of the
  12. REM directory on which this batch file was invoked
  13. ::
  14. dir %1 /a:d/b >%1\lf.$$$
  15. ::
  16. :loop             ;over all dirnames
  17. ::
  18. copy %1\lf.$$$ %1\df.$$$ >nul
  19. ::
  20. REM If there are no more subdirectories to deal with,
  21. REM delete all files and this directory.
  22. ::
  23. if not exist %1\df.$$$ goto cut
  24. ::
  25. REM Create a temporary batch file that will re-invoke
  26. REM PD.BAT on a subdirectory of the current directory.
  27. ::
  28. copy %1\ch.$$$+%1\df.$$$ %1\x.bat >nul
  29. ::
  30. REM Filter out the line that handles the first of the
  31. REM subdirectories in the list, and store the result
  32. REM as the list of remaining directories.
  33. ::
  34. type %1\x.bat | find /v "%0 %1" > %1\lf.$$$
  35. ::
  36. REM Make a recursive call to this batch file, to delete
  37. REM all files and subdirectories in one particular
  38. REM subdirectory.
  39. ::
  40. call %1\x
  41. goto loop
  42. :cut              ;cut-off branch
  43. echo Pruning directory %1
  44. ::
  45. REM Turn off the read-only and hidden attributes for
  46. REM all files in the directory; leave the system attribute
  47. REM so there's no chance of deleting the system files.
  48. ::
  49. attrib -r -h %1\*.* 
  50. echo y | del %1 >nul
  51. rd %1
  52. goto end
  53. :Syntax
  54. echo PD.BAT - Prune Directory
  55. echo SYNTAX:  SET z=^Z
  56. echo          PD [[[drive:\]path\]dirname
  57. :end
  58.