home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / prune.cmd < prev    next >
OS/2 REXX Batch file  |  1995-05-04  |  5KB  |  130 lines

  1. /* ------------------------------------------------------------------------ */
  2. /* PRUNE.CMD                                                                */
  3. /*                                                                          */
  4. /* PRUNE is a utility to remove directory trees. Everything below and       */ 
  5. /* including the directory passed to this routine is deleted and removed.   */
  6. /*                                                                          */
  7. /* Using SysFileTree Prune builds a list of the directories underneath the  */
  8. /* DirPathToPrune specified in the ARGument. For each directory found       */
  9. /* PruneIt will delete all the files within that directory and remove it.   */
  10. /*                                                                          */
  11. /* The directory tree built by SysFileTree is searched backwards because    */
  12. /* the subdirectories are listed in shallow to deep order.                  */
  13. /*                                                                          */
  14. /* Maintenance                                                              */
  15. /* -----------                                                              */
  16. /* 940701DS - #94DS18001                                                    */
  17. /*          - Added logic to check the DirPathToPrune. The user cannot      */
  18. /*            run PRUNE without an argument less than 4 bytes in length.    */
  19. /*                                                                          */
  20. /* 940908DS - #94DS25101                                                    */
  21. /*          - Add logic to keep the directory the same on the target drive  */
  22. /*            specified in the parameter. In other words when checking for  */
  23. /*            the existence of the driectroy to be PRUNED return to the     */
  24. /*            directory that was current before PRUNE was executed.         */
  25. /*                                                                          */
  26. /* ------------------------------------------------------------------------ */
  27. Arg DirPathToPrune
  28.  
  29. Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  30. Call SysLoadFuncs
  31.  
  32. Say "Prune - Directory Tree Remover"
  33. Say " "
  34.  
  35. if length(DirPathToPrune) < 1 then
  36.      Call NoFiles
  37.    else
  38.      if right(DirPathToPrune,1) = '\' then
  39.       Call ErrorMsg
  40.     else
  41.       Call PrunePath
  42. exit
  43.  
  44. /* ------------------------------------------------------------------------ */
  45. /* PrunePath                                                                */
  46. /*                                                                          */
  47. /* ------------------------------------------------------------------------ */
  48. PrunePath:
  49. CurrentDir = directory()
  50.  
  51. TargetDir = filespec("drive",DirPathToPrune)
  52. if TargetDir = '' then
  53.    TargetDir = CurrentDir
  54. else
  55.    TargetDir = directory(TargetDir)
  56.  
  57. DirPathToPrune = directory(DirPathToPrune)
  58.  
  59. call directory TargetDir
  60. call directory CurrentDir
  61.  
  62. if length(DirPathToPrune) > 0 then
  63.      do
  64.        if right(DirPathToPrune,1) = '\' then
  65.         do
  66.           Call ErrorMsg
  67.           Say " "
  68.           Say "NOTE: You may have tried to PRUNE a root directory which is NOT"
  69.           Say "      allowed."
  70.         end
  71.       else
  72.         do
  73.           Say "Searching for files to Prune ..."
  74.           Call SysFileTree DirPathToPrune ||'\*.*', 'Dir', 'DSO'
  75.          
  76.           Say "Pruning" DirPathToPrune ||"\*.* ..."
  77.           i = Dir.0
  78.           do while i > 0
  79.          "@ATTRIB -R -S -H" Dir.i||"\*.* > NUL"
  80.          Call PruneIt Dir.i
  81.          i = i - 1
  82.           end
  83.           Call PruneIt DirPathToPrune
  84.         end
  85.      end
  86.    else
  87.      Call NoFiles
  88.  
  89. Return
  90.  
  91. /* ------------------------------------------------------------------------ */
  92. /* PruneIt                                                                  */
  93. /*                                                                          */
  94. /* ------------------------------------------------------------------------ */
  95. PruneIt:
  96. arg PruneDir
  97.  
  98. Call SysFileTree PruneDir||'\*.*', 'File', 'FO'
  99. Say "Deleting" PruneDir||"\*.* ..."
  100. Do j=1 to File.0
  101.    Call SysFileDelete(File.j)
  102. End 
  103. Call SysRmDir(PruneDir)
  104. Return
  105.  
  106. /* ------------------------------------------------------------------------ */
  107. /* NoFiles                                                                  */
  108. /*                                                                          */
  109. /* ------------------------------------------------------------------------ */
  110. NoFiles:
  111. Say "No Files to PRUNE!"
  112. Return
  113.  
  114. /* ------------------------------------------------------------------------ */
  115. /* Error Message Routine                                                    */
  116. /* ------------------------------------------------------------------------ */
  117. ErrorMsg:
  118. Say "The Directory path to Prune:[" || DirPathToPrune || "] is invalid!" 
  119. Say " "
  120. Say "You must specify a subdirectory name at least 4 bytes long and it "
  121. Say "must NOT end with a \"
  122. Say " "
  123. Say "Command Syntax: PRUNE subdirectoryname"
  124. Say " "
  125. Say "        Example: PRUNE C:\TEMP"
  126. Say "                 PRUNE \TEMP"
  127. Say "                 PRUNE TEMP"
  128. Return
  129.  
  130.