home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / dirtools.zip / DELDIR.CMD < prev    next >
OS/2 REXX Batch file  |  1999-12-13  |  7KB  |  190 lines

  1. /***********************************************************************/
  2. /*DELDIR - starts at the current directory and deletes all files and   */
  3. /*subdirectories in the target, then it deletes the target directory.  */
  4. /*                                                                     */
  5. /*This program supports HPFS long file names.  Simply type in the      */
  6. /*long directory name without quotes. For example this command:        */
  7. /*           DELDIR os!2 2.0 desktop                                   */
  8. /*will delete the desktop directory structure.                         */
  9. /*                                                                     */
  10. /*                                                                     */
  11. /* Written by Mark Polly - Progressive Insurance.                      */
  12. /*            July 2, 1992                                             */
  13. /* Modified by Daniel Hellerstein (danielh@econ.ag.gov), 8 Nov 1998    */
  14. /***********************************************************************/
  15.  
  16. askdel=0
  17.  
  18. ARG user_dir
  19. IF STRIP(user_dir,'B') = '' | strip(user_dir,'B')='?' THEN
  20.     DO 
  21.              SAY 'You must enter a directory name to erase.'
  22.              SAY 'To erase the current directory and all the ones below'
  23.          SAY 'it, use a period (.).'
  24.              EXIT 3
  25.     END
  26.  
  27. /***********************************************************************/
  28. /* Load the OS/2 2.0 RexxUtil DLL and make some functions available    */
  29. /***********************************************************************/
  30.  
  31. CALL RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  32. CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  33. CALL RxFuncAdd 'SysRmDir', 'RexxUtil', 'SysRmDir'
  34.  
  35. /* see if we can load rexxlib */
  36. foo=rxfuncquery('rexxlibregister')
  37. if foo=1 then do
  38.  foo=rxfuncadd('rexxlibregister','rexxlib', 'rexxlibregister')
  39.  if foo=0 then call rexxlibregister
  40. end
  41. foo=rxfuncquery('rexxlibregister')
  42. if foo=1 then  do
  43.  say "Note: this utility works better with the REXXLIB library "
  44.  exit
  45. end
  46.  
  47. gotch=RxFuncQuery('DOSCHMOD')           /* use doschmod if rexxlib is available */
  48.  
  49. /***********************************************************************/
  50. /* Load text strings for SysFileDel and SysRmDir return codes.         */
  51. /***********************************************************************/
  52.  
  53. CALL LoadDELRCText   /* provides text strings for SysFileDel return codes */
  54. CALL LoadRDRCText    /* provides text strings for SysRmDir return codes   */
  55.  
  56. /**************************************************************************/
  57. /*Check to make sure the directory exists - if it does prompt the user to */
  58. /*make sure they really want to do this.   Otherwise issue a message and  */
  59. /*exit                                              */
  60. /**************************************************************************/
  61.  
  62. rc=SysFileTree(user_dir,dir_list, 'D')
  63. IF dir_list.0 = 0  THEN
  64.         DO
  65.              SAY user_dir 'not found, try again.'
  66.              EXIT 1
  67.         END
  68.  
  69. delme=word(dir_list.1,words(dir_list.1))
  70. DROP dir_list.
  71.  
  72. /***********************************************************/
  73. /* Make sure the user really wants to do this              */
  74. /***********************************************************/
  75. say " deleting ... " delme
  76. call charout,'Are you sure? (Y/N)'
  77. PULL answer .
  78. say ''
  79. IF LEFT(answer,1,1) <> 'Y' THEN EXIT 1
  80.  
  81. /***********************************************************/
  82. /* Mark all the read-only files to be non read-only        */
  83. /***********************************************************/
  84.  
  85. rc=SysFileTree(user_dir, dir_list, 'BO', '****','----')
  86.  
  87. DROP dir_list.
  88.  
  89. /***********************************************************/
  90. /* Go through the list of files and delete each one        */
  91. /***********************************************************/
  92.  
  93. rc=SysFileTree(user_dir || '\*.*', dir_list, 'FSO')
  94. DO x = 1 TO dir_list.0
  95.     rc = SysFileDelete(dir_list.x)
  96.         if rc=5 & askdel=0 then do
  97.              say
  98.              call charout, "   Delete readonly files (1=YES)? "
  99.              pull aaa
  100.              if aaa=1 then
  101.                 askdel=1
  102.              else
  103.                 askdel=-1
  104.         end /* do */
  105.         if rc=5 & askdel=1 then do      /* set to non readonly */
  106.           if gotch=1 then do
  107.               fop=doschmod(dir_list.x,,'R')
  108.           end /* do */
  109.           else do
  110.              address cmd '@attrib '||dir_list.x||' -r'
  111.           end
  112.            rc = SysFileDelete(dir_list.x)
  113.         end
  114. /*    SAY dir_list.x ' ........' DELRCText.RC */
  115.     tt= ' ........'||DELRCText.RC||'0d'x
  116.         tt=left(dir_list.x,min(length(dir_list.x),79-length(Tt)))||tt
  117.         call charout,right(tt,79,' ')
  118.  
  119. /*    call charout,left(dir_list.x,min(length(dir_list.x),50)) '........' DELRCText.RC '0d'x */
  120.  
  121. END
  122.  
  123. DROP dir_list.
  124.  
  125. /*************************************************************/
  126. /* Go through all the subdirectories and remove them.        */
  127. /* We go backwards through the list in order to delete the   */
  128. /* lowest level sudirectories first and work our way back up */
  129. /* the tree.                                                 */
  130. /*************************************************************/
  131.  
  132. say 
  133. rc=SysFileTree(user_dir || '\*.*', dir_list, 'DSO')
  134. DO x = dir_list.0 TO 1 BY -1
  135.     rc=SysRmDir(dir_list.x)
  136.     tt= '........'||rdrcText.RC||'0d'x
  137.         tt=left(dir_list.x,min(length(dir_list.x),79-length(Tt)))||tt
  138.         call charout,right(tt,79,' ')
  139. /*    SAY dir_list.x '........' RDRCText.RC */
  140. END
  141.  
  142. DROP dir_list.
  143.  
  144. /**************************************************************/
  145. /* Delete the directory the user passed                */
  146. /**************************************************************/
  147.  
  148. rc=SysRmDir(user_dir)
  149. say 
  150. SAY user_dir '........' RDRCText.RC
  151.  
  152. EXIT 0
  153.  
  154.  
  155. /**************************************/
  156. /* Local subroutines              */
  157. /**************************************/
  158.  
  159. LoadDELRCText:
  160.     /* provides text strings for SysFileDel return codes */
  161.     /* The return codes and strings are in the online Rexx manual */
  162.  
  163.     DELRCText.0 = 'File deleted successfully. '
  164.     DELRCText.2 = 'Error.  File not found. '
  165.     DELRCText.3 = 'Error.  Path not found. '
  166.     DELRCText.5 = 'Error.  Access denied. '
  167.     DELRCText.26 = 'Error.  Not DOS disk. '
  168.     DELRCText.32 = 'Error.  Sharing violation. '
  169.     DELRCText.36 = 'Error.  Sharing buffer exceeded. '
  170.     DELRCText.87 = 'Error.  Invalid parameter. '
  171.     DELRCText.206 = 'Error.  Filename exceeds range error. '
  172. RETURN
  173.  
  174. LoadRDRCText:
  175.     /* provides text strings for SysRmDir return codes */
  176.     /* The return codes and strings are in the online Rexx manual */
  177.  
  178.     RDRCText.0 = 'Directory removal was successful. '
  179.     RDRCText.2 = 'Error.  File not found. '
  180.     RDRCText.3 = 'Error.  Path not found. '
  181.     RDRCText.5 = 'Error.  Access denied. '
  182.     RDRCText.16 = 'Error.  Current Directory. '
  183.     RDRCText.26 = 'Error.  Not DOS disk. '
  184.     RDRCText.87 = 'Error.  Invalid parameter. '
  185.     RDRCText.108 = 'Error.  Drive locked. '
  186.     RDRCText.206 = 'Error.  Filename exceeds range error. '
  187. RETURN
  188.  
  189.  
  190.