Bring value from walk()

Steve Holden sholden at bellatlantic.net
Fri Feb 25 10:06:24 EST 2000


Milos Prudek wrote:
> 
> > 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.

I would love to know if you've found some way to account for the space
occupied by directories, and if you know of some automated way to grab
the clustersize of the partition.

regards
 Steve
--
"If computing ever stops being fun, I'll stop doing it"



More information about the Python-list mailing list