home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
space.cmd
< prev
next >
Wrap
OS/2 REXX Batch file
|
1995-06-28
|
4KB
|
133 lines
/* Catalogue disk space usage. */
/* Author: Brian Plester, May 1995 */
/* Modification History: */
/* */
/* I wrote this little proggy as a way to teach myself REXX */
/* (being an AS/400 RPG programmer at heart). */
/* It served this purpose well, and, as it is a useful little */
/* number, I am publishing it for your perusal and use. */
/* Any constructive criticism will be gratefully received. */
/* Feel free to copy it, distribute it, edit it, and screw it */
/* up however you please. */
/* The program prompts for a drive letter to catalogue. The */
/* user input is verified, and the drive itself is verified. */
/* If all is OK, a directory listing is built and processed */
/* to summarise the number of files and space consumed in the */
/* root and first-level directories. */
say ' '
say 'Space, the final frontier...'
say ' '
/* Open utility functions */
call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
call RxFuncAdd 'SysSleep', 'RexxUtil', 'SysSleep'
call RxFuncAdd 'SysDriveInfo', 'RexxUtil', 'SysDriveInfo'
/* Get drive to catalogue */
say 'Please enter the drive to catalogue.'
say 'NB The '":"' is not necessary: '
pull drive_letter
/* Verify input */
w_error = 0
w_error = verify(drive_letter,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',M)
/* Re-prompt if necessary */
do while w_error = 0
say 'Get your act together and give me a drive LETTER please.'
pull drive_letter
w_error = verify(drive_letter,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',M)
end
/* Strip blanks and colon from input */
drive_letter = strip(drive_letter,B)
drive_letter = strip(drive_letter,T,':')
/* Verify that the requested drive is available */
drive_info = SysDriveInfo(drive_letter':')
if drive_info = ' '
then do
say 'Sorry, drive' drive_letter 'is not available.'
exit
end
/* Get directory tree for specified drive */
drive_letter = drive_letter':\*.*'
say 'Building directory list, please wait...'
call SysFileTree drive_letter , w_list , BS
/* Initialize work variables */
i=1
w_slash = '\'
w_dir_size = 0
w_tot_size = 0
w_files = 0
w_prev = substr(drive_letter , 1 , 3 )
/* Loop to process all entries in directory tree */
do i=1 to w_list.0
/* Call subroutine proc_1 with argument of directory tree entry */
call subr_1 w_list.i
end
/* Output final directory and final total */
say 'Directory' w_prev 'has' w_files 'files,' w_dir_size 'bytes.'
say ' '
say 'Total space used:' w_tot_size 'bytes.'
say ' =' w_tot_size / 1024 'Kb'
say ' =' w_tot_size / 1000000 'MB'
/* End the program */
exit
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Subroutine subr_1 */
subr_1:
/* Get variables from directory tree entry */
parse arg w_date w_time w_size w_mask w_dd
/* Ignore directory entries */
if substr(w_mask , 2 , 1 ) <> 'D'
then do
/* Determine position of 2nd backslash in directory path */
w_position = 0
w_dd = strip(w_dd,L)
w_position = pos(w_slash, w_dd, 4 )
/* Say w_dd */
/* call SysSleep 1 */
/* If position returned is zero, entry is for the root directory */
if w_position = 0
then w_position = 3
/* Store current directory ( drive and 1st directory ) */
w_path = substr(w_dd,1,w_position)
/* If the current directory has changed from last entry, output */
/* totals for previous directory */
if w_path ~= w_prev
then do
say 'Directory' w_prev 'has' w_files 'files,' w_dir_size 'bytes.'
call SysSleep 1
w_tot_size = w_tot_size + w_dir_size
w_dir_size = 0
w_files = 0
end
/* Store current directory and accumulate totals */
w_prev = w_path
w_dir_size = w_dir_size + w_size
w_files = w_files + 1
end
return