Getting the directory size

Steve Tregidgo smst at bigfoot.com
Thu Jun 1 08:24:46 EDT 2000


Pieter Claerhout wrote:
> 
> <code>
[rest of code snipped]
> def main():
> 
>         dir = sys.argv[1]
> 
>         print "Testing directorySize..."
>         print "Directory: %s" %(dir)
>         print "Size: %s %s" %(getDirSize(dir)[0], getDirSize(dir)[1])
> 
> if __name__ == '__main__':
>         main()
> </code>
> 
> Is there any way to fasten up this beauty, because depending on the
> number of directories it has to walk through, it takes a long time. Is
> there maybe a function in the win32 modules who does this for me,
> but lots faster?
> 
I don't know about a dedicated function to do that, but you can double
the speed by changing the last line from:

    print "Size: %s %s" %(getDirSize(dir)[0], getDirSize(dir)[1])

...to the pair of lines:

    amount, units = getDirSize(dir)
    print "Size: %s %s" % (amount, units)

The original version walked the entire structure twice -- once to
calculate the amount, and then again to give the units.  Not really what
you were after, but faster nonetheless.

> Kind regards,
> 
> Pieter Claerhout
> 

HTH a little,
Steve

-- 
Steve Tregidgo
Software Developer
http://www.businesscollaborator.com




More information about the Python-list mailing list