Drive space

Brian Quinlan brian at sweetapp.com
Tue Aug 13 04:50:43 CEST 2002


Trent Mick wrote:
> [Ken Seehof wrote]
> > How do you get the total remaining drive space, given the drive 
> > letter, on Windows?
> 
> Parse the output of "dir" (using os.popen to call it) or learn how to
> use the win32pdh module (part of the PyWin32 extensions, which are
> included in your Python installation if you use ActivePython).

Or you could just use the win32file module:

>>> import win32file
>>> win32file.GetDiskFreeSpaceEx('c:')
[358187008, 40006156288L, 358187008]
>>> # The first number indicates the number of bytes available to 
>>> # the current user. It will be the same as the last number if
>>> # disk quotas aren't on.
>>> print '%dMB disk (%dMB free)' % tuple([i / 1024**2 for i in _[1:]])
38152MB disk (341MB free)
>>> # Looks like I need a new drive

Cheers,
Brian





More information about the Python-list mailing list