free disk space

Roger Burnham roger.burnham at gte.net
Wed Feb 9 13:47:49 EST 2000


On Wed, 09 Feb 2000 07:36:36 GMT, prudek at my-deja.com wrote:

>How can I discover free disk space on a drive in Python (in Win98)? I
>can exec 'dir' and parse output, but is there a nicer way?
>
>--
>Milos Prudek

Milos,

Just had to do this yesterday:

def getFreeSpace(dir):
    """
    Given a directory, return the free space
    (mega bytes) on that drive.
    """
    import os, win32file
    drive = os.path.splitdrive(dir)[0] + os.sep
    fs = win32file.GetDiskFreeSpace(drive)
    fs = int((fs[0]*fs[1]*fs[2])/(1024.0*1024.0))
    return fs


Roger Burnham   
Cambridge Research & Instrumentation   
rburnham at cri-inc.com   
http://www.cri-inc.com/   
http://starship.python.net/crew/roger/   
PGP Key: http://www.nai.com/default_pgp.asp   
PGP Fingerprint: 5372 729A 9557 5F36 177F  084A 6C64 BE27 0BC4 CF2D   



More information about the Python-list mailing list