calculate system disk space

Heiko Wundram modelnine at bit-bukket.org
Sat Dec 10 00:57:11 CET 2005


PyPK wrote:
> I am looking for unix.the recipe is windows specific!!

Parse the output of du/df? :-) I guess that would be simplest... ;-)

Otherwise, use some combination of os.walk() and os.stat(), whereby you
_don't_ use the stat.st_size field to get the file size (on disk) but
rather use stat.st_blocks*stat.st_blksize to get it, as you might come
across so called sparse files which are bigger than their on-disk
representation.

For explanations, see:

http://www.python.org/doc/2.4.2/lib/os-file-dir.html
(entries for stat() and walk())

--- Heiko.



More information about the Python-list mailing list