Bring value from walk()
Milos Prudek
prudek at nembv.cz
Fri Feb 25 06:12:47 EST 2000
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.
The problem is that Filespace is Zero at the end. Fs is reset to Zero
every time walk gets called, so I thought I would add Total variable
(lines with Total are currently commented out), but I got NameError:
Total.
Is there (an object oriented) way to bring Total from Estimatespace thru
EstDirSpace right back into main program?
def Estimatespace(Fs, Dirn, Nams):
print Dirn
for X in Nams:
Fs=Fs+os.stat(Dirn+'/'+X)[stat.ST_SIZE]
print '-',X,Fs
# Total=Total+Fs
return
def EstDirSpace(RootDir):
Filespace=0
# Total=0
os.path.walk(RootDir, Estimatespace, Filespace)
print "end of walk, Filespace=",Filespace
return Filespace
EstSpace=EstDirSpace('c:/DL/ati')
--
Milos Prudek
More information about the Python-list
mailing list