home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / diskutil.zip / otregone.cmd < prev    next >
OS/2 REXX Batch file  |  1999-10-08  |  2KB  |  60 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 is not being deleted and that there is an argument */
  24. curdir = directory()
  25. IF Arg(1) = ""
  26.     Then 
  27.         Do    
  28.         Say "No Path specified"
  29.         Exit
  30.         End
  31.  
  32. /* Delete Directory */
  33.  
  34. rc = SysRmDir(Arg(1))
  35. /* check to make sure directory to be deleted is deleteable */
  36. If rc = 0
  37.     Then call SysRmDir Arg(1)
  38.            
  39. Else
  40.     If rc = 5  /* Attempts to remove any readonly bits then deletes files and finally rd directories */
  41.         Then
  42.         Do
  43.             call SysFileTree Arg(1)'\*.*', 'file', 'BSO', '***+*', '***-*'  /* removes readonly bit */
  44.             call SysFileTree Arg(1)'\*.*', 'file', 'FSO'
  45.                 do i=1 to file.0
  46.                     call SysFileDelete file.i  /* deletes files in directories */
  47.                 end
  48.             call SysFileTree Arg(1)'\*.*', 'direct', 'SDO'
  49.             i = direct.0
  50.              
  51.             do while i<>0
  52.                 call SysRmDir direct.i /* deletes directories in tree in necessary order */
  53.                 i = i - 1
  54.             end 
  55.             call SysRmDir Arg(1) /* deletes initial directory */
  56.         end    
  57.          
  58. Exit
  59.  
  60.