Public Sub FileSizeStrings( ByVal fileSize, ByRef sizes )
Const K_SIZE = 1024
Set sizes = CreateObject( "Scripting.Dictionary" )
fileSize = CDbl( fileSize )
sizes.Add "Bytes", Cstr( fileSize )
tmpSize = CDbl( fileSize / K_SIZE )
sizes.Add "KB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "MB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "GB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "TB", Cstr( tmpSize )
tmpSize = CDbl( tmpSize / K_SIZE )
sizes.Add "PB", Cstr( tmpSize )
End Sub
This nice function will convert a size string to a size string representation in various units. the ByRef sizes parameter is converted to a Dictionary in the Sub. then a calculation is performed for every unit offsets of 1K.
Call FileSizeStrings( "5000000000", sizes )
For Each key In sizes.Keys
Print sizes( key ) & " " & key
Next
The output would be :
Posted in FileSystemObject


daniva




Recent Comments