home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / dab.cmd < prev    next >
OS/2 REXX Batch file  |  1994-05-19  |  4KB  |  156 lines

  1. /*  
  2. ** Delete All But  
  3. **
  4. ** by Mark Ziller
  5. ** 
  6. ** based on code by Jeff Elkins 
  7. **
  8. */
  9.  
  10.  
  11. /* first, setup VRexx calls */
  12. '@echo off'
  13. call RxFuncAdd 'VInit', 'VREXX', 'VINIT'
  14. initcode = VInit()
  15. if initcode = 'ERROR' then signal CLEANUP
  16. signal on failure name E_CLEAN
  17. signal on halt name E_CLEAN
  18. signal on syntax name E_CLEAN
  19.  
  20. /* Then load Rexx Utility Functions */
  21. CALL RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  22. CALL RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
  23.  
  24.  
  25. /* Give program info */
  26. say 'Delete All But (DAB) by Mark Ziller, 1994'
  27. say
  28.  
  29. /* if the user didn't pass any arguments, give them an error box */
  30. ARG ext1 ext2 ext3 ext4 ext5 ext6 ext7 ext8 ext9 ext10
  31. IF STRIP(ext1,'B') = '' THEN
  32.     DO 
  33.         msg.0 = 5
  34.         msg.1 = 'Usage:'
  35.         msg.2 = '   DAB <template1> <...> <template10>'
  36.         msg.3 = ''
  37.         msg.4 = 'Example:'
  38.         msg.5 = '   DAB *.exe *.cmd *.com'
  39.         call VDialogPos 50, 50
  40.         call VMsgBox 'Delete All But (DAB)', msg, 1
  41.             signal CLEANUP
  42.     END
  43.  
  44. t.1  = ext1
  45. t.2  = ext2
  46. t.3  = ext3
  47. t.4  = ext4
  48. t.5  = ext5
  49. t.6  = ext6
  50. t.7  = ext7
  51. t.8  = ext8
  52. t.9  = ext9
  53. t.10 = ext10
  54.  
  55.  
  56. file_error.2   = 'Error:  File not found : '
  57. file_error.3   = 'Error:  Path not found : '
  58. file_error.5   = 'Error:  Access denied : '
  59. file_error.26  = 'Error:  Not DOS disk : '
  60. file_error.32  = 'Error:  Sharing violation : '
  61. file_error.36  = 'Error:  Sharing buffer exceeded : '
  62. file_error.87  = 'Error:  Invalid parameter : '
  63. file_error.206 = 'Error:  Filename exceeds range error : '
  64.  
  65.  
  66. /***********************************************************/
  67. /* hide the files to be kept                               */
  68. /***********************************************************/
  69.  
  70. DO x = 1 TO 10
  71. ext = t.x
  72. IF STRIP(ext,'B') <> '' THEN
  73.    rc=SysFileTree(ext, dir_list, 'F', '*****','**+**')
  74. END
  75.  
  76.  
  77. /**************************************************************/
  78. /* pull the files to be deleted into a stem, then delete them */
  79. /**************************************************************/
  80.  
  81.  
  82. rc=SysFileTree('*.*', del_file, 'FO', '**-**','*****')
  83.  
  84. df = del_file.0
  85. fn = 0
  86.  
  87. /* now show a check list box to let the user select which files to delete */
  88. call VDialogPos 50,50
  89. result = VListBox('Files to be deleted',del_file, 35, 10, 3)
  90. if result = 'CANCEL' then do
  91.     /*    msg.0 = 1
  92.         msg.1 = 'No Files Deleted'
  93.           call VMsgBox 'Operation Canceled', msg, 1 */
  94.         say 'DAB: Operation canceled. No files deleted.'
  95.     signal UNHIDE
  96.     end
  97.  
  98.  
  99.  
  100. /* open a window for showing deleted files */
  101.  
  102. win.left   = 20
  103. win.right  = 70
  104. win.top    = 80
  105. win.bottom = 40
  106. id = VOpenWindow('Deleting files...', 'BLUE', win)
  107.  
  108. call VForeColor id, 'WHITE'
  109. call VSetFont id, 'TIME', 14
  110.  
  111. x = 10
  112. y = 900
  113.  
  114. /* otherwise, delete the files */
  115. do z = 1 to df
  116.            rc = SysFileDelete(del_file.z)
  117.     if rc = 0 then
  118.         text = z || ' : Deleting: ' || del_file.z
  119.     else
  120.         text = z || ' : ' file_error.rc || del_file.z
  121.     call VSay id, x, y, text
  122.     y = y - 60
  123.     if y <= 0 then do
  124.         call VClearWindow id
  125.         y = 900
  126.         end
  127.     end
  128. call VCloseWindow id
  129. say 'DAB: ' df ' files deleted.'
  130. say
  131.  
  132.  
  133.  
  134. /**************************************************************/
  135. /* unhide the hidden files                                    */
  136. /**************************************************************/
  137. UNHIDE:
  138. DO x = 1 TO 10
  139. ext = t.x
  140. IF STRIP(ext,'B') <> '' THEN
  141.    rc=SysFileTree(ext, dir_list, 'F', '**+**','**-**')
  142. END
  143.  
  144.  
  145.  
  146. /* end of CMD file */
  147.  
  148. CLEANUP:
  149.    call VExit
  150. exit
  151.  
  152. E_CLEAN:
  153.    call VExit
  154.    say 'DAB: Error. Operation aborted.'
  155.    say
  156. exit