Bring value from walk()
sholden at bellatlantic.net
Fri Feb 25 16:03:50 CET 2000
Milos Prudek wrote:
> I need a function that walks the dir tree and adds up occupied space.
> This is the source. "print Dirn", "print '-',X,Fs" and "print End of
> walk..." lines are for debugging only.
This isn't classed up, but might do what you want.
I'm sure it could be optimized: this is NOT production code.
def usage(path, names, verbose=0):
sum = 0
dirs = 
files = 
for name in names:
n = os.path.join(path,name)
for d in dirs:
sum = sum + usage(d, os.listdir(d), verbose)
for f in files:
l = os.path.getsize(f)
sum = sum + l
if verbose: print "%s %d" % (f, l)
print "%s %d" % (path, sum)
"If computing ever stops being fun, I'll stop doing it"
More information about the Python-list