Bring value from walk()

Milos Prudek prudek at
Fri Feb 25 15:21:26 CET 2000

> You need a mutable object. Making Fs a list with one
> element, (initialized to 0), and then totalling into Fs[0] will do
> the trick.

Thanks for great explanation. This is the final, working code:

import os, os.path, stat

def EstimSpace(Fs, Dirn, Nams):
    for X in Nams:

def EstDirSpace(RootDir):
    os.path.walk(RootDir, EstimSpace, Fs)
    return Fs[0]

print "Estimated space is",EstDirSpace('c:/Program Files/Python')

Of course, next task will be rounding up the estimate of every file to
cluster size of target disk drive... that will be easy.

Milos Prudek

More information about the Python-list mailing list