home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / space.cmd < prev    next >
OS/2 REXX Batch file  |  1995-06-28  |  4KB  |  133 lines

  1. /*  Catalogue disk space usage.                                */
  2. /*  Author: Brian Plester, May 1995                           */
  3. /*  Modification History:                                     */
  4. /*                                                            */
  5.  
  6. /* I wrote this little proggy as a way to teach myself REXX   */
  7. /* (being an AS/400 RPG programmer at heart).                 */
  8. /* It served this purpose well, and, as it is a useful little */
  9. /* number, I am publishing it for your perusal and use.       */
  10. /* Any constructive criticism will be gratefully received.    */
  11. /* Feel free to copy it, distribute it, edit it, and screw it */
  12. /* up however you please.                                     */
  13.  
  14.  
  15. /* The program prompts for a drive letter to catalogue. The   */
  16. /* user input is verified, and the drive itself is verified.  */
  17. /* If all is OK, a directory listing is built and processed   */
  18. /* to summarise the number of files and space consumed in the */
  19. /* root and first-level directories.                          */
  20.  
  21. say ' '
  22. say 'Space, the final frontier...'
  23. say ' '
  24.  
  25. /* Open utility functions */
  26. call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
  27. call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
  28. call RxFuncAdd 'SysDriveInfo', 'RexxUtil', 'SysDriveInfo'
  29.  
  30. /* Get drive to catalogue */
  31. say 'Please enter the drive to catalogue.'
  32. say 'NB The '":"' is not necessary: '
  33. pull drive_letter
  34.  
  35. /* Verify input */
  36. w_error = 0
  37. w_error = verify(drive_letter,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',M)
  38.  
  39. /* Re-prompt if necessary */
  40. do while w_error = 0 
  41.   say 'Get your act together and give me a drive LETTER please.'
  42.   pull drive_letter
  43.   w_error = verify(drive_letter,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',M)
  44. end
  45.  
  46. /* Strip blanks and colon from input */
  47. drive_letter = strip(drive_letter,B)
  48. drive_letter = strip(drive_letter,T,':')
  49.  
  50. /* Verify that the requested drive is available */
  51. drive_info = SysDriveInfo(drive_letter':')
  52. if drive_info = ' '
  53.   then do
  54.     say 'Sorry, drive' drive_letter 'is not available.'
  55.     exit
  56.   end
  57.  
  58. /* Get directory tree for specified drive */
  59. drive_letter = drive_letter':\*.*'
  60. say 'Building directory list, please wait...'
  61. call SysFileTree drive_letter , w_list , BS
  62.  
  63. /* Initialize work variables */
  64. i=1
  65. w_slash = '\'
  66. w_dir_size = 0
  67. w_tot_size = 0
  68. w_files    = 0
  69. w_prev = substr(drive_letter , 1 , 3 )
  70.  
  71. /* Loop to process all entries in directory tree */
  72. do i=1 to w_list.0
  73.  
  74.   /* Call subroutine proc_1 with argument of directory tree entry */
  75.   call subr_1 w_list.i
  76.  
  77. end
  78.  
  79. /* Output final directory and final total */
  80. say 'Directory' w_prev 'has' w_files 'files,' w_dir_size 'bytes.'
  81. say ' '
  82. say 'Total space used:' w_tot_size 'bytes.'
  83. say '                =' w_tot_size / 1024 'Kb' 
  84. say '                =' w_tot_size / 1000000 'MB' 
  85.  
  86. /* End the program */
  87. exit
  88.  
  89.  
  90. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  91. /* Subroutine subr_1 */
  92. subr_1:
  93.  /* Get variables from directory tree entry */
  94.  parse arg w_date w_time w_size w_mask w_dd
  95.  
  96. /* Ignore directory entries */
  97. if substr(w_mask , 2 , 1 ) <> 'D'
  98.   then do
  99.  
  100.     /* Determine position of 2nd backslash in directory path */
  101.     w_position = 0
  102.     w_dd = strip(w_dd,L)
  103.     w_position = pos(w_slash, w_dd, 4 ) 
  104.  
  105.     /* Say w_dd        */
  106.     /* call SysSleep 1 */
  107.  
  108.     /* If position returned is zero, entry is for the root directory */
  109.     if w_position = 0 
  110.       then w_position = 3
  111.  
  112.     /* Store current directory ( drive and 1st directory ) */
  113.     w_path = substr(w_dd,1,w_position)
  114.  
  115.     /*  If the current directory has changed from last entry, output */
  116.     /* totals for previous directory */ 
  117.     if w_path ~= w_prev 
  118.       then do
  119.          say 'Directory' w_prev 'has' w_files 'files,' w_dir_size 'bytes.'
  120.  
  121.          call SysSleep 1
  122.  
  123.          w_tot_size = w_tot_size + w_dir_size
  124.          w_dir_size = 0
  125.          w_files = 0
  126.          end
  127.  
  128.     /* Store current directory and accumulate totals */
  129.     w_prev = w_path
  130.     w_dir_size = w_dir_size + w_size
  131.     w_files = w_files + 1
  132.   end
  133. return