home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / diskutil.zip / treegone.cmd < prev    next >
OS/2 REXX Batch file  |  1999-12-03  |  2KB  |  67 lines

  1. /* Delete Directory tool */
  2. /* Define Rexx Functions */
  3.  
  4. call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  5. call RxFuncAdd 'SysRmDir', 'RexxUtil', 'SysRmDir'
  6. call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  7. call RxFuncAdd 'SysGetKey', 'RexxUtil', 'SysGetKey'
  8. /* Make sure that this is truly what you want */
  9. say "Is this TRULY what you want?  (Y/N)"
  10. sure:
  11. key = SysGetKey(noecho)    
  12. select
  13.      when key = 'n'
  14.         then exit
  15.     when key = 'N'
  16.         then exit
  17.     when key <> 'y' 
  18.         then If key <> 'Y'
  19.             then signal sure
  20. Otherwise
  21. end
  22.  
  23. /* Check to make sure that the current directory (or previous or root) is not being deleted and that there is an argument */
  24.  
  25. select    
  26.     when Arg(1) = ""
  27.         then signal bye    
  28.     when Arg(1) = '.'
  29.         then signal bye
  30.     when Arg(1) = '..'
  31.         then signal bye
  32.     when Arg(1) = '\'
  33.         then signal bye
  34. Otherwise  
  35. End
  36.  
  37. /* Delete Directory */
  38.  
  39. rc = SysRmDir(Arg(1))
  40. /* check to make sure directory to be deleted is deleteable */
  41. If rc = 0
  42.     Then call SysRmDir Arg(1)
  43.            
  44. Else
  45.     If rc = 5  /* Attempts to remove any readonly bits then deletes files and finally rd directories */
  46.         Then
  47.         Do
  48.             call SysFileTree Arg(1)'\*.*', 'file', 'BSO', '***+*', '***-*'  /* removes readonly bit */
  49.             call SysFileTree Arg(1)'\*.*', 'file', 'FSO'
  50.                 do i=1 to file.0
  51.                     call SysFileDelete file.i  /* deletes files in directories */
  52.                 end
  53.             call SysFileTree Arg(1)'\*.*', 'direct', 'SDO'
  54.             i = direct.0
  55.              
  56.             do while i<>0
  57.                 call SysRmDir direct.i /* deletes directories in tree in necessary order */
  58.                 i = i - 1
  59.             end 
  60.             call SysRmDir Arg(1) /* deletes initial directory */
  61.         end    
  62.          
  63. Exit
  64.  
  65. bye:
  66.     say 'Invalid or nonexistent directory'
  67. exit