Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for deldir.cmd

(view source code of deldir.cmd as plain text)

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

page last modified: 2024-04-16; loaded in 0.0120 seconds