postprocessing in os.walk
Paul Rubin
http
Tue Oct 13 09:29:03 EDT 2009
kj <no.email at please.post> writes:
> I think you're missing the point. The hook in question has to be
> called *immediately after* all the subtrees that are rooted in
> subdirectories contained in the current directory have been visited
> by os.walk.
>
> I'd love to see your "5 lines" for *that*.
I'm having trouble understanding the specification. To find the disk
usage (in bytes) of a directory:
import os,stat
def find_disk_usage(dirname):
return sum(sum(os.stat(dirpath+'/'+filename)[stat.ST_SIZE]
for filename in fn_list)
for dirpath, dirlist, fn_list in os.walk(dirname))
More information about the Python-list
mailing list