home *** CD-ROM | disk | FTP | other *** search
/ Mega Top 1 / os2_top1.zip / os2_top1 / APPS / PROG / C_PLUS / CNVLIB2 / DELTREE2.CMD < prev    next >
Encoding:
Text File  |  1993-06-24  |  1.8 KB  |  60 lines

  1. @echo off
  2. REM DelTree2 - Delete a directory, including all files and subdirectories.  This
  3. REM            is quicker than DelTree1 because it works one directory at a time.
  4. if "%1"=="" GOTO SHOW_HOW
  5.  
  6. :This is a dangerious function, so make sure they really want it
  7.    ECHO THIS WILL DELETE ALL FILES AND DIRECTORIES UNDER %1
  8.    CALL GetUKey.cmd "ARE YOU SURE YOU WANT TO DELETE DO THIS? (Y/N)"    yn
  9.    if N==%UKEY% GOTO FINI
  10.  
  11. :Check that it is a valid file name
  12.    CEnvi ValidDir.cmd %1 COMPLAIN
  13.    if ERRORLEVEL 1 GOTO FINI
  14.  
  15. :Unset attributes so that all files can be deleted
  16.    attrib -H -S -R %1\* /s > NUL
  17.  
  18. :Delete each directory
  19.    dir %1 /Ad /f /s /On | cenvi #include '%0,cmd,,GOTO END_SOURCE,:END_SOURCE'
  20.  
  21.    GOTO END_SOURCE
  22.  
  23.       // Create list of all the sub-directories
  24.       DirCount = 0
  25.       while ( NULL != (DirName = gets()) ) {
  26.          if ( DirName[strlen(DirName)-1] != '.' )  // dot and double-dot aren't sub-directories
  27.             strcpy(DirList[DirCount++],DirName)
  28.       }
  29.       // for each directory in that list delete all the files and then the directory.
  30.       // Do this in reverse order because it's in reverse order so we won't
  31.       // try to delete a directory while it still has subdirectories.
  32.       for ( i = DirCount; i != 0; i-- ) {
  33.          DirName = DirList[i-1]
  34.          sprintf(Command,"echo Y | del %s\\* > NUL",DirName)
  35.          printf("DEL %s\\*\n",DirName)
  36.          system(Command)
  37.          sprintf(Command,"RMDIR %s",DirName)
  38.          printf("%s\n",Command)
  39.          system(Command)
  40.       }
  41.  
  42.    :END_SOURCE
  43.  
  44. :Finally, delete the directory itself
  45.    ECHO DEL %1\*
  46.    ECHO Y | DEL %1\*
  47.    ECHO RMDIR %1
  48.    RMDIR %1 > NUL
  49. GOTO FINI
  50.  
  51.  
  52. :SHOW_HOW
  53. ECHO  
  54. ECHO DelTree2.cmd - Delete this directory and all files and subdirectories within it.
  55. ECHO  
  56. GOTO FINI
  57.  
  58. :FINI
  59. set UKEY=
  60.