Format filesize in kB or MB

Discussion in 'ASP .Net' started by Arjen, Aug 8, 2003.

  1. Arjen

    Arjen Guest

    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!
    Arjen, Aug 8, 2003
    #1
    1. Advertising

  2. Arjen

    eruess Guest

    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" <> wrote in message
    news:bh0qmo$jt9$1.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!
    >
    >
    eruess, Aug 8, 2003
    #2
    1. Advertising

  3. Arjen

    Jerry III Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    Jerry III, Aug 9, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Colliver

    Problem retrieving filesize

    David Colliver, May 17, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    365
    David Colliver
    May 17, 2005
  2. =?Utf-8?B?ZG90bmV0dGVzdGVy?=

    Response.writefile (filename) ?? problem with filesize

    =?Utf-8?B?ZG90bmV0dGVzdGVy?=, Aug 16, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    488
    Buddy Ackerman
    Aug 16, 2005
  3. VB Programmer

    How check filesize using FileUpload control?

    VB Programmer, Jan 18, 2006, in forum: ASP .Net
    Replies:
    11
    Views:
    20,329
  4. Michel Rosien

    STL Stream maximum filesize?

    Michel Rosien, Sep 18, 2003, in forum: C++
    Replies:
    8
    Views:
    610
    Mike Wahler
    Sep 18, 2003
  5. Rainer Goerke

    filesize of an ofstream

    Rainer Goerke, May 7, 2004, in forum: C++
    Replies:
    6
    Views:
    9,549
    Mike Wahler
    May 9, 2004
Loading...

Share This Page