Format filesize in kB or MB

  • Thread starter Thread starter Arjen
  • Start date Start date
A

Arjen

Hello,

When I have read a file with x.xxx.xxx.xxx bytes it is sometimes handy to
show it in an diverent format than bytes.

Is there a handy way to do this?
Or is there a function for it?

When it is a big file I want to see a MB size and when it is a lower file
size then I want to see a kB size for example.

Thanks!
 
It shouldn't be too much trouble to do it by hand, right? Like what about
this psuedo code:

select case filesize
case >= 1,000,000,000,000
(display) filesize \ 1,000,000,000,000 & " TB?"
case >= 1,000,000,000
(display) filesize \ 1,000,000,000 & " GB"
case >= 1,000,000
(display) filesize \ 1,000,000 & " MB"
case >= 1,000
(display) filesize \ 1,000 & " KB"
case else
(display) filesize & " bytes"
end select
 
Actually Windows API provides such a function,
StrFormatByteSizeA/StrFormatByteSizeW. If you really wanted to you could use
that (through a COM object?).

Jerry
 
Back
Top