[Tutor] Getting "file sizes"

R. Alan Monroe amonroe at columbus.rr.com
Wed Feb 18 20:29:46 EST 2004


> Yes, I can get the file size of an individual file by specifying the
> complete path. But if I have a directory with 60 files then I would 
> have to manually put the path in for each file in that directory that I 
> wish to know the size of.
> [snip]
> What I don't understand is how to get Python to use the "getsize()" 
> function for each file that the "os.listdir('/var/log/portage')" 
> function lists. 


This isn't recursive, but for a single directory it would work:

[(x,os.path.getsize(x)) for x in os.listdir('c:/')]



Alan




More information about the Tutor mailing list