check disc space

Fredrik Lundh fredrik at pythonware.com
Thu Dec 11 01:58:36 EST 2003


"T. Schulz" wrote:

> I wonder if it would be worthwhile to have such a functionality
> somewhere in the os module?

two counter-arguments:

- the os module is traditionally used to provide access to posix-style
services provided by the OS (or the C library).  in this case, os.statvfs
is such a function; calling out to "du" isn't

(shouldn't that be "df", btw? os.popen("du -k dir").split()[-5] sure
doesn't give the free diskspace on any platform I have access to...)

- what you mean with "free disc space" may depend on the platform
and the application; os.statvfs provides lots of additional information
that you can use on a Unix platform, and there are similar (but not
identical) metrics available on Windows.

(a third argument is that "free disc space" is a rather meaningless metric
on a modern operating system; it's hardly ever useful for anything except
"warning, warning, less than 5% free space" alerts.  you really don't want
people to write "if os.getfreespace() >= len(buffer): f.write(buffer)" and
file a bug when write fails ;-)

</F>








More information about the Python-list mailing list