[python-win32] Size of directory
Mark Hammond
mhammond at skippinet.com.au
Sun Apr 27 08:52:36 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:
> http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/86554
The above uses os.listdir(), which I've had problems with in the past with
huge directories (I can't recall, but I suspect it was simply performance
that sucked). Either way, the fastest I've come up with has been based
around:
for fd in win32file.FindFilesIterator(os.path.join(dir, "*")):
name = fd[8]
if name in ('.', '..'):
continue
See the docs for how the 'fd' tuple is laid out.
Cheers,
Mark
More information about the python-win32
mailing list