Bring value from walk()

Milos Prudek prudek at nembv.cz
Fri Feb 25 09:21:26 EST 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:
        Fs[0]=Fs[0]+os.stat(Dirn+'/'+X)[stat.ST_SIZE]
    return

def EstDirSpace(RootDir):
    Fs=[]
    Fs.append(0) 
    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