home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
spcsave.zip
/
SPCSAVE.CMD
Wrap
OS/2 REXX Batch file
|
1995-05-08
|
15KB
|
367 lines
/* ADDUPEAS.CMD This REXX program looks at specified drive */
/* and lists all files to determine the total amount of */
/* EA space that should be used on the drive in file */
/* EA DATA. SF given that each EA takes one cluster of */
/* a FAT formatted disk. This will not match exactly the */
/* size of the EA file since ... well I don't know why but */
/* it consistently reports one less cluster on my system */
/* than the size of EA DATA. SF really is. */
/* Author Trevor Hemsley - 95/04/30 */
Call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
Call SysLoadFuncs
inputfile = "C:\temp\filelist.txt" /* this is the file to DIR to */
outputfile = "C:\temp\ealist.txt" /* file to contain the list */
file_with_ea = 0 /* initialise counter */
ea_amounts = 0 /* initialise counters */
dir_count = 0
tot_file_size = 0
tot_clusters = 0
tot_clustersHPFS = 0
tot_clusters64 = 0
tot_clusters128 = 0
tot_clusters256 = 0
tot_clusters512 = 0
tot_clusters1024 = 0
ea_totals = 0
ea_amountsHPFS = 0
ea_amounts64 = 0
ea_amounts128 = 0
ea_amounts256 = 0
ea_amounts512 = 0
ea_amounts1024 = 0
cluster_sizeHPFS = 512
cluster_size64 = 2048
cluster_size128 = 4096
cluster_size256 = 8192
cluster_size512 = 16382
cluster_size1024 = 32768
rx = SysFileTree("C:\TEMP",rx.,"D") /* test existence of temp dir*/
if rx.0 = 0 then
do
say "Directory C:\TEMP does not exist. Create it Y/N?"
parse upper pull answer
if answer ¬= "Y" then exit
else
do
"@MD C:\TEMP"
end
end
rx = stream(inputfile,"c","query exists") /* test existence of file */
if rx ¬= "" then /* to stop from overwriting */
do
say "Warning - existing file "inputfile" will be overwritten. Continue Y/N?"
answer = SysGetKey("NOECHO")
parse upper var answer answer
if answer ¬= "Y" then exit
else
"@del "inputfile
end
rx = stream(outputfile,"c","query exists") /* test existence of file */
if rx ¬= "" then
do
say "Warning - existing file "outputfile" will be overwritten. Continue Y/N?"
answer = SysGetKey("NOECHO")
parse upper var answer answer
if answer ¬= "Y" then exit
else
"@del "outputfile
end
say "Please maximise this window and reply any character to continue"
answer = SysGetKey("NOECHO")
"@MODE co80,29" /* accidently make the OS/2 session large enough to display all lines */
do while drive_letter = "DRIVE_LETTER" /* Ask which drive to process */
say "Which disk drive letter do you wish to examine (eg C) ?"
drive_letter = SysGetKey("NOECHO")
if DATATYPE(drive_letter,"M") = 1 then
do
drive_letter=drive_letter||":"
end
else drive_letter = "DRIVE_LETTER"
end
disk_info = sysdriveinfo(drive_letter)
disk_size = word(disk_info,3)
disk_used_space = word(disk_info,3) - word(disk_info,2)
real_size = stream(drive_letter"\EA DATA. SF","c","Query size")
if real_size = "" then
do
say "Could not find file EA DATA. SF - this must be run against a FAT disk"
exit
end
if disk_size > 64*1024*1024 then cluster_size=2048
if disk_size > 128*1024*1024 then cluster_size=4096
if disk_size > 256*1024*1024 then cluster_size=8192
if disk_size > 512*1024*1024 then cluster_size=16384
if disk_size > 1024*1024*1024 then cluster_size=32768
say "Listing file information from "word(disk_info,1)". Please wait..."
"@dir "drive_letter"\ /a /s /n >"inputfile
if rc¬=0 then
do
say "Non-zero return code ("rc") from DIR. Ending Rexx exec."
exit
end
say "Now checking for EA's. This may take some time..."
rc = TIME("R")
do while lines(inputfile) ¬= 0 /* repeat for each line in input file */
rx = linein(inputfile) /* read next record from input file */
if words(rx) = 0 then iterate /* ignore blank lines */
if word(rx,1) = "The" then iterate /* ignore all lines that meet the... */
if word(rx,1) = "Directory" then /* ...criteria listed here */
do
dir_count = dir_count + 1
iterate
end
if word(rx,2) = "file(s)" then iterate
if word(rx,2) = "files" then iterate
if word(rx,2) = "bytes" then iterate
if word(rx,5) ¬= "EA" && word(rx,6) ¬= "DATA." && word(rx,7) ¬= "SF" then
do
if word(rx,3) ¬= "<DIR>" then
do
file_size = word(rx,3)
if file_size//cluster_size = 0 then
file_clusters = (file_size%cluster_size)
else
file_clusters = (file_size%cluster_size)+1
if file_size//cluster_sizeHPFS = 0 then
file_clustersHPFS = (file_size%cluster_sizeHPFS)
else
file_clustersHPFS = (file_size%cluster_sizeHPFS)+1
if file_size//cluster_size64 = 0 then
file_clusters64 = (file_size%cluster_size64)
else
file_clusters64 = (file_size%cluster_size64)+1
if file_size//cluster_size128 = 0 then
file_clusters128 = (file_size%cluster_size128)
else
file_clusters128 = (file_size%cluster_size128)+1
if file_size//cluster_size256 = 0 then
file_clusters256 = (file_size%cluster_size256)
else
file_clusters256 = (file_size%cluster_size256)+1
if file_size//cluster_size512 = 0 then
file_clusters512 = (file_size%cluster_size512)
else
file_clusters512 = (file_size%cluster_size512)+1
if file_size//cluster_size1024 = 0 then
file_clusters1024 = (file_size%cluster_size1024)
else
file_clusters1024 = (file_size%cluster_size1024)+1
tot_file_size = tot_file_size+file_size
tot_clusters = tot_clusters+file_clusters
tot_clustersHPFS = tot_clustersHPFS+file_clustersHPFS
tot_clusters64 = tot_clusters64+file_clusters64
tot_clusters128 = tot_clusters128+file_clusters128
tot_clusters256 = tot_clusters256+file_clusters256
tot_clusters512 = tot_clusters512+file_clusters512
tot_clusters1024 = tot_clusters1024+file_clusters1024
end /* Do if word(rx,3) ne <dir> */
end /* Do if word(rx,5) ne EA DATA. SF */
if word(rx,4) = 0 then iterate
else
do /* this line is for a file with EA's */
file_with_ea = file_with_ea + 1 /* add 1 to count of files found */
ry = LINEOUT(outputfile,rx) /* write this line to output file */
ea_amount=word(rx,4) /* extract size of EA's for this file*/
ea_totals=ea_totals+ea_amount /* keep running total of amount used */
if ea_amount//cluster_size = 0 then /* determine how many... */
this_file_ea=(ea_amount%cluster_size) /* clusters the EA's take up */
else
this_file_ea=(ea_amount%cluster_size)+1 /* round up cluster numbers */
ea_amounts=ea_amounts+this_file_ea /* keep running total */
if ea_amount//cluster_size64 = 0 then /* determine how many... */
this_file_ea64=(ea_amount%cluster_size64)/* clusters the EA's take */
else
this_file_ea64=(ea_amount%cluster_size64)+1 /* round cluster numbers*/
ea_amounts64=ea_amounts64+this_file_ea64 /* keep running total */
if ea_amount//cluster_size128 = 0 then /* determine how many... */
this_file_ea128=(ea_amount%cluster_size128)/* clusters the EA's take*/
else
this_file_ea128=(ea_amount%cluster_size128)+1 /* round clust numbers*/
ea_amounts128=ea_amounts128+this_file_ea128 /* keep running total */
if ea_amount//cluster_size256 = 0 then /* determine how many... */
this_file_ea256=(ea_amount%cluster_size256)/* clusters the EA's take*/
else
this_file_ea256=(ea_amount%cluster_size256)+1 /* round clust numbers*/
ea_amounts256=ea_amounts256+this_file_ea256 /* keep running total */
if ea_amount//cluster_size512 = 0 then /* determine how many... */
this_file_ea512=(ea_amount%cluster_size512)/* clusters the EA's take*/
else
this_file_ea512=(ea_amount%cluster_size512)+1 /* round clust numbers*/
ea_amounts512=ea_amounts512+this_file_ea512 /* keep running total */
if ea_amount//cluster_size1024 = 0 then /* determine how many... */
this_file_ea1024=(ea_amount%cluster_size1024)/* clusters the EA's*/
else
this_file_ea1024=(ea_amount%cluster_size1024)+1 /* round clust nums */
ea_amounts1024=ea_amounts1024+this_file_ea1024 /* keep running total*/
end /* end of DO word(rx,4) = 0 */
end /* End of DO WHILE LINES(INPUTFILE) */
rc = TIME("E")
Say "Gathering information took "rc" seconds"
say "Size of drive "word(disk_info,1)" is "disk_size" with a cluster size of "cluster_size
ea_file_size = ea_amounts*cluster_size
Say "Number of files with EA's is "file_with_ea" making EA DATA. SF approx. "ea_file_size
size_difference = real_size-(ea_amounts*cluster_size)
Say " "
Say "Difference between calculated size and actual size is "size_difference
If size_difference/cluster_size <= 3 then
say "This is probably nothing to worry about ! (I mean it's normal)"
else
say "You may want to run CHKDSK "drive_letter" /F against this drive to double check."
z = stream(inputfile,"c",close) /* close input file */
z = stream(outputfile,"c",close) /* close output file */
Say "List of files with EA's is in "outputfile ". Do you wish to keep this?"
answer = SysGetKey("NOECHO")
parse upper var answer answer /* pull answer */
if answer = "Y" | answer ="YES" then
do
"@del "inputfile /* clean up after us */
Say "Sorting file into EA size order ..."
"@sort /+32 /R <"outputfile" >"inputfile
"@del "outputfile
"@copy "inputfile" "outputfile" >nul"
"@del "inputfile
end
else
do
"@del "outputfile
"@del "inputfile
end
dir_space = cluster_size*(dir_count+1)
ea_waste = 0+(ea_amounts * cluster_size) - ea_totals
file_waste = disk_used_space - tot_file_size
disk_used_space = format(disk_used_space,10)
tot_file_size = format(tot_file_size,12)
ea_totals = format(ea_totals,12)
dir_space = format(dir_space,11)
ea_waste = format(ea_waste,10)
file_waste = format(file_waste,10)
say " "
say " Space wasted by"
say " Total Space Extended Directory incomplete clusters"
say " Space Used for files Attributes Space by EA's by Files"
say disk_used_space" "tot_file_size" "ea_totals" "dir_space" "ea_waste" "file_waste
say " "
/*
Space for Files is the number of bytes the actual file takes up.
Extended Attributes is the nuber of bytes the actual EA's take up
Directory space is a guess assuming each directory uses a cluster
Wasted by EA's is the number of clusters used by EA's minus the actual size
Wasted by files is the number of clusters the files consume minus the actual file size
Wasted means unused in this context
*/
say "By my calculations, the space that would be consumed by your files if you"
say "repartitioned your disk as smaller FAT partitions or an HPFS partition would be:"
spc_usedHPFS = tot_clustersHPFS*cluster_sizeHPFS+dir_space
spc_used64 = tot_clusters64*cluster_size64+dir_space
spc_used128 = tot_clusters128*cluster_size128+dir_space
spc_used256 = tot_clusters256*cluster_size256+dir_space
spc_used512 = tot_clusters512*cluster_size512+dir_space
spc_used1024 = tot_clusters1024*cluster_size1024+dir_space
spc_usedHPFS = format(spc_usedHPFS,10)
spc_used64 = format(spc_used64,10)
spc_used128 = format(spc_used128,10)
spc_used256 = format(spc_used256,10)
spc_used512 = format(spc_used512,10)
spc_used1024 = format(spc_used1024,10)
spc_ea64 = ea_amounts64*cluster_size64
spc_ea128 = ea_amounts128*cluster_size128
spc_ea256 = ea_amounts256*cluster_size256
spc_ea512 = ea_amounts512*cluster_size512
spc_ea1024 = ea_amounts1024*cluster_size1024
spc_eaHPFS = format(ea_totals,8)
spc_ea64 = format(spc_ea64,8)
spc_ea128 = format(spc_ea128,8)
spc_ea256 = format(spc_ea256,8)
spc_ea512 = format(spc_ea512,8)
spc_ea1024 = format(spc_ea1024,8)
/* trace "i" */
spc_savHPFS = cluster_size*tot_clusters+ea_file_size-(spc_usedHPFS+ea_totals)+dir_space
spc_sav64 = cluster_size*tot_clusters + ea_file_size - (spc_used64+spc_ea64)+dir_space
spc_sav128 = cluster_size*tot_clusters + ea_file_size - (spc_used128+spc_ea128)+dir_space
spc_sav256 = cluster_size*tot_clusters + ea_file_size - (spc_used256+spc_ea256)+dir_space
spc_sav512 = cluster_size*tot_clusters + ea_file_size - (spc_used512+spc_ea512)+dir_space
spc_sav1024 = cluster_size*tot_clusters + ea_file_size - (spc_used1024+spc_ea1024)+dir_space
if SIGN(spc_savHPFS) < 0 then
spc_savHsign = "loss"
else spc_savHsign = " "
spc_savHPFS = format(ABS(spc_savHPFS),10)
if SIGN(spc_sav64) < 0 then
spc_sav64sign = "loss"
else spc_sav64sign = " "
spc_sav64 = format(ABS(spc_sav64),10)
if SIGN(spc_sav128) < 0 then
spc_sav128sign = "loss"
else spc_sav128sign = " "
spc_sav128 = format(ABS(spc_sav128),10)
if SIGN(spc_sav256) < 0 then
spc_sav256sign = "loss"
else spc_sav256sign = " "
spc_sav256 = format(ABS(spc_sav256),10)
if SIGN(spc_sav512) < 0 then
spc_sav512sign = "loss"
else spc_sav512sign = " "
spc_sav512 = format(ABS(spc_sav512),10)
if SIGN(spc_sav1024) < 0 then
spc_sav1024sign = "loss"
else spc_sav1024sign = " "
spc_sav1024 = format(ABS(spc_sav1024),10)
say "Partition Space Size of Space"
say " size used EA DATA. SF saving"
say "========== ========= =========== =========="
say "HPFS drive "spc_usedHPFS" "spc_eaHPFS" "spc_savHPFS" "spc_savHsign
say "64-127Mb "spc_used64" "spc_ea64" "spc_sav64" "spc_sav64sign
say "128-255Mb "spc_used128" "spc_ea128" "spc_sav128" "spc_sav128sign
say "256-511Mb "spc_used256" "spc_ea256" "spc_sav256" "spc_sav256sign
say "512-1023Mb "spc_used512" "spc_ea512" "spc_sav512" "spc_sav512sign
say "1024-2047Mb "spc_used1024" "spc_ea1024" "spc_sav1024" "spc_sav1024sign