By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,264 Members | 1,725 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,264 IT Pros & Developers. It's quick & easy.

Format filesize in kB or MB

P: n/a
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!
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

"Arjen" <bo*****@hotmail.com> wrote in message
news:bh**********@news2.tilbu1.nb.home.nl...
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!

Nov 17 '05 #2

P: n/a
Actually Windows API provides such a function,
StrFormatByteSizeA/StrFormatByteSizeW. If you really wanted to you could use
that (through a COM object?).

Jerry

"Michal A. Valasek" <ne**@altaircom.net> wrote in message
news:OJ**************@TK2MSFTNGP09.phx.gbl...
Hello,

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

there is no specific function to do that. Go the way "eruess" provided, but keep in mind, that kB, MB etc. is binary, not decimal, and use
multiplications of 1024, not 1000.

--
Michal A. Valasek, Altair Communications, http://www.altaircom.net
Please do not reply to this e-mail, for contact see http://www.rider.cz

Nov 17 '05 #3

P: n/a
Actually Windows API provides such a function,
StrFormatByteSizeA/StrFormatByteSizeW. If you really wanted to you could use
that (through a COM object?).

Jerry

"Michal A. Valasek" <ne**@altaircom.net> wrote in message
news:OJ**************@TK2MSFTNGP09.phx.gbl...
Hello,

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

there is no specific function to do that. Go the way "eruess" provided, but keep in mind, that kB, MB etc. is binary, not decimal, and use
multiplications of 1024, not 1000.

--
Michal A. Valasek, Altair Communications, http://www.altaircom.net
Please do not reply to this e-mail, for contact see http://www.rider.cz

Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.