[Tutor] Getting "file sizes"
Joshua Banks
syn_ack at comcast.net
Wed Feb 18 19:44:49 EST 2004
On Wednesday 18 February 2004 01:22 pm, you wrote:
> Ah, a Gentoo fan. *grin*
Yes, I luv Gentoo... :P
> Ah, you know about os.path.getsize() already then. getsize() is
> actually more versatile than you might think: have you tried applying
> it on an individual file path?
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.
Example: The following gives me a list of the files in the directory
specified below. There's a total of 12 files listed for examples sake.
>>> os.listdir('/var/log/portage')
['1782-openmotif-2.1.30-r3.log', '1781-iptables-1.2.8-r1.log',
'1756-slocate-2.7-r5.log', '1763-xloadimage-4.1-
r1.log', '1773-iproute-20010824-r4.log',
'1757-gentoo-sources-2.4.22-r5.log', '1788-tcl-8.3.4.log', '1797-libpe
rl-5.8.0.log', '1769-python-2.3.3.log', '1776-xfree-drm-4.3.0-r6.log',
'1806-ymessenger-1.0.4.1.log', '1766-win
e-20031118-r1.log']
I also understand that I can do the following 12 times, specifying a
different file each time and get the "file size answers that I'm
looking for. So I understand how to do this the HardWay.
>>> os.path.getsize('/var/log/portage/1782-openmotif-2.1.30-r3.log')
39L
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.
I've read and read and read. I don't understand, what seems, would be a
simple task. Having to manually input each file, one at a time seems
backwards to the progamming moto. Do more with less so to say.
I'm I not making any sense? Any idea's on how I can get this to work?
Thanks,
Joshua Banks
More information about the Tutor
mailing list