[Tutor] Re: Getting "file sizes" !Sovled!! For real.. Heh..Heh..

Blake Winton bwinton at latte.ca
Thu Feb 26 13:07:40 EST 2004


> Blake can you provide me with a quick example of using 
> os.walk.path and os.path.join using my example?

Sadly, no, because I'm insanely busy at work, and because I
don't use os.path.walk all that often, so I don't remember
how to use it.  Hopefully one of the other tutors will jump
in to the discussion now, and show you something simple to
understand, which still being very powerful.  ;)

I can give you this modification to your example, though:

> import os, os.path
> dirname = "c:\\Documents and Settings\\jj\\Desktop\\"
> a = os.listdir(dirname)
> for x in a:
>     print x, os.path.getsize(dirname + x)

import os, os.path
dirname = "c:\\Documents and Settings\\jj\\Desktop\\"
a = os.listdir(dirname)
for x in a:
    fullPath = os.path.join( dirname, x );
    if os.path.isdir( fullPath ):
        b = os.listdir( fullPath )
        for y in b:
            fullSubPath = os.path.join( dirname, x, y )
            print x, "->" , y, os.path.getsize( fullSubPath )
    print x, os.path.getsize( os.path.join( dirname, x ) )

does that help at all?

Later,
Blake.




More information about the Tutor mailing list