size of a file
eppstein at ics.uci.edu
Tue Jul 24 22:24:05 CEST 2001
In article <3b5dd418_8 at news.newsgroups.com>,
"Janos Blazi" <jblazi at hotmail.com> wrote:
> How can I find out the length of a file. I have a descriptor fd of the file
> (I am using the os module).
When I wanted to do this recently, I used
f = open(fn) # open file, fn is a string containing the filename
f.seek(0,2) # go to end of file
fsize = f.tell()
I guess if you already have an fd you could skip the call to open() and
seek back to the start in place of the close().
No doubt someone will tell me a better way to do this...
David Eppstein UC Irvine Dept. of Information & Computer Science
eppstein at ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list