[Python-Dev] Function in os module for available disk space, why not?

M.-A. Lemburg mal@lemburg.com
Mon, 19 Mar 2001 14:07:25 +0100


Dinu Gherman wrote:
> 
> "M.-A. Lemburg" wrote:
> >
> > I think the problem with this one really is the differences
> > in OS designs, e.g. on Windows you have the concept of drive
> > letters where on Unix you have mounted file systems. Then there
> > also is the concept of disk space quota per user which would
> > have to be considered too.
> 
> I'd be perfectly happy with something like this:
> 
>   import os
>   free = os.getfreespace('c:\\')          # on Win
>   free = os.getfreespace('/hd5')          # on Unix-like boxes
>   free = os.getfreespace('Mactintosh HD') # on Macs
>   free = os.getfreespace('ZIP-1')         # on Macs, Win, ...
> 
> etc. where the string passed is, a-priori, a name known
> by the OS for some permanent or removable drive. Network
> drives might be slightly more tricky, but probably not
> entirely impossible, I guess.

This sounds like a lot of different platform C APIs would need
to be wrapped first, e.g. quotactrl, getrlimit (already done)
+ a bunch of others since "get free space" is usually a file system
dependent call.

I guess we should take a look at how "df" does this on Unix
and maybe trick Mark Hammond into looking up the win32 API ;-)

> > Perhaps what we really need is some kind of probing function
> > which tests whether a certain amount of disk space would be
> > available ?!
> 
> Something like incrementally stuffing it with junk data until
> you get an exception, right? :)

Yep. Actually opening a file in record mode and then using
file.seek() should work on many platforms.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company & Consulting:                           http://www.egenix.com/
Python Pages:                           http://www.lemburg.com/python/