How to find size of file?

Discussion in 'Python' started by Walter Huf, Mar 5, 2004.

  1. Walter Huf

    Walter Huf Guest

    Hi, I'm the same one with the CGI download problem. This time, however, I
    want to send the client the size of the file that will be downloaded. How
    would I find the size of the file, so I can include that in the headers?

    --Walter Huf--

    http://hufman.cobalty.com


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
     
    Walter Huf, Mar 5, 2004
    #1
    1. Advertising

  2. Walter Huf wrote:
    > Hi, I'm the same one with the CGI download problem. This time, however, I
    > want to send the client the size of the file that will be downloaded. How
    > would I find the size of the file, so I can include that in the headers?


    >>> import os
    >>> os.stat("c:/tmp/x.html").st_size

    567L

    -- Gerhard
     
    =?ISO-8859-1?Q?Gerhard_H=E4ring?=, Mar 5, 2004
    #2
    1. Advertising

  3. Walter Huf

    Yermat Guest

    Walter Huf a écrit :

    > Hi, I'm the same one with the CGI download problem. This time, however, I
    > want to send the client the size of the file that will be downloaded. How
    > would I find the size of the file, so I can include that in the headers?
    >
    > --Walter Huf--
    >
    > http://hufman.cobalty.com
    >
    >
    > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----


    def sizeOf(f):
    f.seek(0,2)
    return f.tell()
     
    Yermat, Mar 5, 2004
    #3
  4. Walter Huf

    Walter Huf Guest

    Yermat <1.nerim.net> wrote in
    news:c2ai0g$1t4u$:

    > Walter Huf a écrit :


    > def sizeOf(f):
    > f.seek(0,2)
    > return f.tell()
    >


    Thank you!


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
     
    Walter Huf, Mar 5, 2004
    #4
  5. Yermat wrote:


    > def sizeOf(f):
    > f.seek(0,2)
    > return f.tell()
    >


    Hm. For better performance (and readability) try os.path.getsize(filename).....

    --Irmen
     
    Irmen de Jong, Mar 5, 2004
    #5
  6. Hi,

    Other ways:

    >> import os, stat
    >> os.stat(filename)[stat.ST_SIZE]


    Or better:

    >> import os.path
    >> os-path.getsize(filename)


    Best regards,
    Iñigo Serna

    El vie, 05-03-2004 a las 22:13, Walter Huf escribió:
    > Yermat <1.nerim.net> wrote in
    > news:c2ai0g$1t4u$:
    >
    > > Walter Huf a écrit :

    >
    > > def sizeOf(f):
    > > f.seek(0,2)
    > > return f.tell()
    > >

    >
    > Thank you!
    >
    >
    > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----



    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.3 (GNU/Linux)

    iD8DBQBAScPqfN63/+cBjZoRAg/kAJ422p6BEUwf+V8VxYiY3IBCDucp7wCgw3v0
    HU7YGWzVPR8SoBpweVVYSTc=
    =LJwG
    -----END PGP SIGNATURE-----
     
    =?ISO-8859-1?Q?I=F1igo?= Serna, Mar 6, 2004
    #6
    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. tiewknvc9
    Replies:
    6
    Views:
    673
    Chris Uppal
    Oct 1, 2006
  2. Jason Cavett

    Preferred Size, Minimum Size, Size

    Jason Cavett, May 23, 2008, in forum: Java
    Replies:
    5
    Views:
    12,655
    Michael Jung
    May 25, 2008
  3. Keith Thompson

    Re: File Size - Big File Size

    Keith Thompson, Oct 1, 2009, in forum: C Programming
    Replies:
    6
    Views:
    300
    Phil Carmody
    Oct 3, 2009
  4. Michael Tsang

    Re: File Size - Big File Size

    Michael Tsang, Oct 4, 2009, in forum: C Programming
    Replies:
    2
    Views:
    329
    Keith Thompson
    Oct 4, 2009
  5. Nobody

    Re: File Size - Big File Size

    Nobody, Oct 5, 2009, in forum: C Programming
    Replies:
    10
    Views:
    2,052
    Flash Gordon
    Oct 10, 2009
Loading...

Share This Page