home *** CD-ROM | disk | FTP | other *** search
- A sample BATCH file to delete a subdirectory and all its subdirectories.
- @ECHO OFF
- REM
- REM RDSTAR, a BATCH file to do a recursive operation on a directory subtree
- REM %1=the disk name, a CAPITAL LETTER and colon
- REM %2=a complete pathname starting with \, in ALL CAPITAL LETTERS
- REM
- REM first, see if a valid pathname in %1
- IF zip%2==zip GOTO missorno
- IF NOT %2==\ GOTO notroot1
- IF NOT EXIST %1\.\NUL GOTO missorno
- GOTO rootok
- :notroot1
- IF NOT EXIST %1%2\.\NUL GOTO missorno
- :rootok
- ECHO All subdirectories of %1%2 will be destroyed!
- ECHO:
- ECHO Do you really want to do this? (Press ENTER to continue, Ctrl-C to quit)
- PAUSE > NUL
- REM second, get list of directories to be operated on
- REM In case clusters messed up, give CHKDSK an input answer of "n"
- ECHO n > %1\star$tmp.$1$
- CHKDSK %1 /V > %1\star$tmp.$2$ < %1\star$tmp.$1$
- IF NOT %2==\ GOTO notroot2
- FIND "Directory %1" %1\star$tmp.$2$ > %1\star$tmp.$1$
- GOTO third
- :notroot2
- FIND "Directory %1%2" %1\star$tmp.$2$ > %1\star$tmp.$1$
- :third
- REM third, use DEBUG to create files controlling EDLINs
- ECHO n star$del.$0$> %1\star$tmp.$3$
- ECHO e 0100 "1,#RDirectoryzDELdaEda">> %1\star$tmp.$3$
- ECHO e 010D 1A>> %1\star$tmp.$3$
- ECHO e 0111 0D 0A>> %1\star$tmp.$3$
- ECHO e 0114 0D 0A>> %1\star$tmp.$3$
- ECHO rcx>> %1\star$tmp.$3$
- ECHO 0016>> %1\star$tmp.$3$
- ECHO w>> %1\star$tmp.$3$
- ECHO n star$rd$.$0$>> %1\star$tmp.$3$
- ECHO e 010E "RD ">> %1\star$tmp.$3$
- ECHO w>> %1\star$tmp.$3$
- ECHO n star$y$$.$0$>> %1\star$tmp.$3$
- ECHO e 010E "Y ">> %1\star$tmp.$3$
- ECHO w>> %1\star$tmp.$3$
- ECHO q>> %1\star$tmp.$3$
- DEBUG < %1\star$tmp.$3$ > NUL
- ECHO 1,2D>star$hdr.$0$
- IF NOT %2==\ GOTO notroot3
- ECHO 1,3D>star$hdr.$0$
- :notroot3
- ECHO E>>star$hdr.$0$
- REM fourth, sort the list to operate from bottom to top of tree structure
- EDLIN %1\star$tmp.$1$ < star$hdr.$0$ > NUL
- DEL %1\star$tmp.bak
- SORT /R < %1\star$tmp.$1$ > star$del.bat
- REM fifth, use EDLIN to produce batch files to DEL and RM each subdirectory
- EDLIN star$del.bat < star$del.$0$ > NUL
- REN star$del.bak star$rd$.bat
- EDLIN star$rd$.bat < star$rd$.$0$ > NUL
- REN star$rd$.bak star$y$$.bat
- EDLIN star$y$$.bat < star$y$$.$0$ > NUL
- REM sixth, DEL each subdirectory, with a "y" response
- COMMAND /C star$del < star$y$$.bat > NUL
- IF %2==\ DEL %1\*.* < star$y$$.bat > NUL
- REM seventh, RD each subdirectory
- COMMAND /C star$rd$ > NUL
- REM eighth, clean up all temporary files
- IF EXIST star$???.$?$ DEL star$???.$?$
- IF EXIST star$???.ba? DEL star$???.ba?
- IF EXIST %1\star$tmp.$?$ DEL %1\star$tmp.$?$
- GOTO eexxiitt
- :missorno
- ECHO Missing or invalid pathname
- :EEXXIITT
- EXIT