home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / RD!.ZIP / RD!.CMD
OS/2 REXX Batch file  |  1993-03-28  |  3KB  |  83 lines

  1. /*-----------------------------------------------------------------------+
  2. |                                                                        |
  3. | RD!.CMD - Removes entire HPFS or FAT directory structures.             |
  4. |           Nothing stands in it's way.                                  |
  5. |                                                                        |
  6. +-----------------------------------------------------------------------*/
  7. parse upper arg target_dir
  8.  
  9. say
  10. if queued()>0 then call drainq
  11. if target_dir\='' then do
  12.    call wipeout
  13. end
  14. else do
  15.    say 'RD! - Remove a directory, and all subdirectories.'
  16.    say '      Supports FAT and HPFS.  Exercise Caution...'
  17.    say
  18.    say '    -> SYNTAX: RD! UTILITY'
  19.    say '               RD! OS!2 2.0 Desktop'
  20. end
  21. bailout:
  22. exit
  23.  
  24. Wipeout:
  25. '@CD "'target_dir'" 1>NUL 2>NUL'
  26. if rc\=0 then do
  27.    say '->' time()", Target directory dosen't exist."
  28.    signal bailout
  29. end
  30. say '->' time()', Resetting attributes.'
  31. '@ATTRIB *.* -R -S -H /S 1>NUL 2>NUL'
  32. if rc\=0 then do
  33.    say '  ' time()', Global attribute change failed.'
  34. end
  35. say '  ' time()', Processing directory structure.'
  36. call load_structure
  37. say '  ' time()', Removing files and subdirectories.'
  38. i=1
  39. if words(dir_list)>0 then do i=i+1 until dir_list=''
  40.    parse value dir_list with '"'data'"' dir_list
  41.    '@DEL "'data'\*.*" /N 1>NUL 2>NUL'  /* delete files */
  42.    '@RD  "'data'"        1>NUL 2>NUL'  /* remove dir   */
  43.    if rc\=0 then do
  44.       say '  ' time()', Could not remove:('data').'
  45.    end
  46. end
  47. '@DEL *.* /N 1>NUL 2>NUL'           /* delete files in 1st level */
  48. if rc\=0 then do
  49.    say '  ' time()', Some files in 'target_dir' not removed.'
  50. end
  51. '@CD..'                             /* surface to base level     */
  52. '@RD "'target_dir'" 1>NUL 2>NUL'    /* remove 1st level          */
  53. if rc=0 then do
  54.    say '  ' time()', Task complete,' i 'directories removed.'
  55. end
  56. else do
  57.    say '  ' time()', Unable to completely remove' target_dir'.'
  58. end
  59. return
  60.  
  61. Load_Structure:
  62. file_list='';dir_list=''
  63. /*----------------------------------------------------------+
  64. | /S      - All subdirectories.                             |
  65. | /AD     - Only show directory names.                      |
  66. | /B      - Don't include directory header or trailer info. |
  67. | 2>NUL   - Send error output (if any) to null.             |
  68. | SORT    - Sort /R (reverse order) the directory output.   |
  69. | RXQUEUE - Pump it onto the stack for REXX to read.        |
  70. +----------------------------------------------------------*/
  71. '@DIR /S /AD /B 2>NUL | SORT /R | RXQUEUE'
  72. do i=1 to queued()
  73.    parse pull data
  74.    if data\='' then dir_list=dir_list '"'data'"'
  75. end
  76. return
  77.  
  78. drainq:
  79. do queued()
  80.    parse pull .
  81. end
  82. return
  83.