win32: computing sizes of directories

Alex Martelli aleaxit at
Fri Nov 10 20:56:26 CET 2000

"Les Schaffer" <godzilla at> wrote in message
news:87n1f7pyop.fsf at
> i was looking for a fast way to compute the size of a subdirectory in
> wondows (unix: 'du -s dirName' ) on specific directories in windows
> and i looked through the win32 extensions and couldnt find anything.
> but i am guessing its in there somewhere. anyone know?

Sure!  For such tasks, I generally find that the object-models
of the "Scripting Runtime" and "Windows Scripting Host", as
accessed by COM, are handiest.  For example:

import win32com.client

def subdirsize(path):
    fso = win32com.client.Dispatch("Scripting.FileSystemObject")
    f = fso.GetFolder(path)
    print "Folder %s takes, in all, %d bytes" % (path, f.size)

if __name__=='__main__':


More information about the Python-list mailing list