home *** CD-ROM | disk | FTP | other *** search
- @echo off
- REM DelTree2 - Delete a directory, including all files and subdirectories. This
- REM is quicker than DelTree1 because it works one directory at a time.
- if "%1"=="" GOTO SHOW_HOW
-
- :This is a dangerious function, so make sure they really want it
- ECHO THIS WILL DELETE ALL FILES AND DIRECTORIES UNDER %1
- CALL GetUKey.cmd "ARE YOU SURE YOU WANT TO DELETE DO THIS? (Y/N)" yn
- if N==%UKEY% GOTO FINI
-
- :Check that it is a valid file name
- CEnvi ValidDir.cmd %1 COMPLAIN
- if ERRORLEVEL 1 GOTO FINI
-
- :Unset attributes so that all files can be deleted
- attrib -H -S -R %1\* /s > NUL
-
- :Delete each directory
- dir %1 /Ad /f /s /On | cenvi #include '%0,cmd,,GOTO END_SOURCE,:END_SOURCE'
-
- GOTO END_SOURCE
-
- // Create list of all the sub-directories
- DirCount = 0
- while ( NULL != (DirName = gets()) ) {
- if ( DirName[strlen(DirName)-1] != '.' ) // dot and double-dot aren't sub-directories
- strcpy(DirList[DirCount++],DirName)
- }
- // for each directory in that list delete all the files and then the directory.
- // Do this in reverse order because it's in reverse order so we won't
- // try to delete a directory while it still has subdirectories.
- for ( i = DirCount; i != 0; i-- ) {
- DirName = DirList[i-1]
- sprintf(Command,"echo Y | del %s\\* > NUL",DirName)
- printf("DEL %s\\*\n",DirName)
- system(Command)
- sprintf(Command,"RMDIR %s",DirName)
- printf("%s\n",Command)
- system(Command)
- }
-
- :END_SOURCE
-
- :Finally, delete the directory itself
- ECHO DEL %1\*
- ECHO Y | DEL %1\*
- ECHO RMDIR %1
- RMDIR %1 > NUL
- GOTO FINI
-
-
- :SHOW_HOW
- ECHO
- ECHO DelTree2.cmd - Delete this directory and all files and subdirectories within it.
- ECHO
- GOTO FINI
-
- :FINI
- set UKEY=