File and directory size converter
Posted: Sun Nov 03, 2013 2:10 pm
Hello all,
Here is a procedure that can convert file and directory sizes specified in bytes up to petabytes.
WARNING: you also need the constants, because PB is unable to work with functions specified in CASE statements.
Erion
Here is a procedure that can convert file and directory sizes specified in bytes up to petabytes.
WARNING: you also need the constants, because PB is unable to work with functions specified in CASE statements.
Code: Select all
#pow210=1024
#pow220=1048576
#pow230=1073741824
#pow240=1099511627776
#pow250=1125899906842624
#pow260=1152921504606846976
Procedure.s FileSizeConvert(bytes.q)
Protected output.s
Select bytes
Case 0 To #pow210 ; bytes
output = StrD(bytes,2)+" B"
Case #pow210 To #pow220 ;kilobytes
output = StrD(bytes/#pow210,2)+" KB"
Case #pow220 To #pow230 ;megabytes
output = StrD(bytes/#pow220,2)+" MB"
Case #pow230 To #pow240 ;gigabytes
output = StrD(bytes/#pow230,2)+" GB"
Case #pow240 To #pow250 ;terabytes
output = StrD(bytes/#pow240,2)+" TB"
Case #pow250 To #pow260 ;petabytes
output = StrD(bytes/#pow250,2)+" PB"
EndSelect
ProcedureReturn output
EndProcedure