[python-win32] Size of directory

Dahlstrom, Roger rdahlstrom at directedge.com
Tue Apr 22 20:20:41 CEST 2008

You have to walk the directory tree and sum each file's size.  Windows does this too - try your right-click properties on a large directory and see how long it
takes.  That's also what du does.  There are, however, some recipes that should make this fairly simple for you - try this:


From: python-win32-bounces+rdahlstrom=directedge.com at python.org [mailto:python-win32-bounces+rdahlstrom=directedge.com at python.org] On Behalf Of Tony Cappellini
Sent: Tuesday, April 22, 2008 2:03 PM
To: python-win32 at python.org
Subject: [python-win32] Size of directory

When I right click on a directory with windows Explorer, a window is displayed showing

Size On Disk:
(with the appropriate values for each entry)

How do I get the same information via Python ?

I've looked at os.stat but 


only returns the size of a "plain file" :(

It's really a shame that windows doesn't have a built-in tool to show you a tree of subdirectories, and how much space is occupied by each subdirectory.

I guess I need to roll my own- once I know what the underlying call is to get the size of each directory

This e-mail, and any attachments thereto, is intended only for use by the addressee(s) named herein and
may contain legally privileged and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination, distribution or copying of this e-mail, and 
any attachments thereto, is strictly prohibited. If you have received this in error, please immediately notify 
me and permanently delete the original and any copy of any e-mail and any printout thereof. 
E-mail transmission cannot be guaranteed to be secure or error-free. The sender therefore does not accept 
liability for any errors or omissions in the contents of this message which arise as a result of e-mail transmission.

Direct Edge ECN LLC may, at its discretion, monitor and review the content of all e-mail communications.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20080422/1b0ad7fd/attachment.htm>

More information about the python-win32 mailing list