home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / DELDIR.CMD < prev    next >
OS/2 REXX Batch file  |  1992-07-27  |  6KB  |  143 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. /*                                                                     */
  14. /***********************************************************************/
  15.  
  16. ARG user_dir
  17. IF STRIP(user_dir,'B') = '' THEN
  18.     DO 
  19.              SAY 'You must enter a directory name to erase.'
  20.              SAY 'To erase the current directory and all the ones below'
  21.          SAY 'it, use a period (.).'
  22.              EXIT 3
  23.     END
  24.  
  25. /***********************************************************************/
  26. /* Load the OS/2 2.0 RexxUtil DLL and make some functions available    */
  27. /***********************************************************************/
  28.  
  29. CALL RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  30. CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  31. CALL RxFuncAdd 'SysRmDir', 'RexxUtil', 'SysRmDir'
  32.  
  33. /***********************************************************************/
  34. /* Load text strings for SysFileDel and SysRmDir return codes.         */
  35. /***********************************************************************/
  36.  
  37. CALL LoadDELRCText   /* provides text strings for SysFileDel return codes */
  38. CALL LoadRDRCText    /* provides text strings for SysRmDir return codes   */
  39.  
  40. /**************************************************************************/
  41. /*Check to make sure the directory exists - if it does prompt the user to */
  42. /*make sure they really want to do this.   Otherwise issue a message and  */
  43. /*exit                                              */
  44. /**************************************************************************/
  45.  
  46. rc=SysFileTree(user_dir,dir_list, 'D')
  47. IF dir_list.0 = 0  THEN
  48.         DO
  49.              SAY user_dir 'not found, try again.'
  50.              EXIT 1
  51.         END
  52.  
  53. DROP dir_list.
  54.  
  55. /***********************************************************/
  56. /* Make sure the user really wants to do this              */
  57. /***********************************************************/
  58.  
  59. SAY 'Are you sure? (Y/N)'
  60. PULL answer .
  61. IF LEFT(answer,1,1) <> 'Y' THEN EXIT 1
  62.  
  63. /***********************************************************/
  64. /* Mark all the read-only files to be non read-only        */
  65. /***********************************************************/
  66.  
  67. rc=SysFileTree(user_dir, dir_list, 'BO', '****','----')
  68.  
  69. DROP dir_list.
  70.  
  71. /***********************************************************/
  72. /* Go through the list of files and delete each one        */
  73. /***********************************************************/
  74.  
  75. rc=SysFileTree(user_dir || '\*.*', dir_list, 'FSO')
  76. DO x = 1 TO dir_list.0
  77.     rc = SysFileDelete(dir_list.x)
  78.     SAY dir_list.x '........' DELRCText.RC
  79. END
  80.  
  81. DROP dir_list.
  82.  
  83. /*************************************************************/
  84. /* Go through all the subdirectories and remove them.        */
  85. /* We go backwards through the list in order to delete the   */
  86. /* lowest level sudirectories first and work our way back up */
  87. /* the tree.                                                 */
  88. /*************************************************************/
  89.  
  90. rc=SysFileTree(user_dir || '\*.*', dir_list, 'DSO')
  91. DO x = dir_list.0 TO 1 BY -1
  92.     rc=SysRmDir(dir_list.x)
  93.     SAY dir_list.x '........' RDRCText.RC
  94. END
  95.  
  96. DROP dir_list.
  97.  
  98. /**************************************************************/
  99. /* Delete the directory the user passed                */
  100. /**************************************************************/
  101.  
  102. rc=SysRmDir(user_dir)
  103. SAY user_dir '........' RDRCText.RC
  104.  
  105. EXIT 0
  106.  
  107.  
  108. /**************************************/
  109. /* Local subroutines              */
  110. /**************************************/
  111.  
  112. LoadDELRCText:
  113.     /* provides text strings for SysFileDel return codes */
  114.     /* The return codes and strings are in the online Rexx manual */
  115.  
  116.     DELRCText.0 = 'File deleted successfully. '
  117.     DELRCText.2 = 'Error.  File not found. '
  118.     DELRCText.3 = 'Error.  Path not found. '
  119.     DELRCText.5 = 'Error.  Access denied. '
  120.     DELRCText.26 = 'Error.  Not DOS disk. '
  121.     DELRCText.32 = 'Error.  Sharing violation. '
  122.     DELRCText.36 = 'Error.  Sharing buffer exceeded. '
  123.     DELRCText.87 = 'Error.  Invalid parameter. '
  124.     DELRCText.206 = 'Error.  Filename exceeds range error. '
  125. RETURN
  126.  
  127. LoadRDRCText:
  128.     /* provides text strings for SysRmDir return codes */
  129.     /* The return codes and strings are in the online Rexx manual */
  130.  
  131.     RDRCText.0 = 'Directory removal was successful. '
  132.     RDRCText.2 = 'Error.  File not found. '
  133.     RDRCText.3 = 'Error.  Path not found. '
  134.     RDRCText.5 = 'Error.  Access denied. '
  135.     RDRCText.16 = 'Error.  Current Directory. '
  136.     RDRCText.26 = 'Error.  Not DOS disk. '
  137.     RDRCText.87 = 'Error.  Invalid parameter. '
  138.     RDRCText.108 = 'Error.  Drive locked. '
  139.     RDRCText.206 = 'Error.  Filename exceeds range error. '
  140. RETURN
  141.  
  142.  
  143.