Determining disk space

Mark Pilgrim f8dy at yahoo.com
Tue Feb 27 15:51:31 CET 2001


"Gary Quinn" <gary at esands.com> wrote in message
news:3A9B2ABA.AFFC65EC at esands.com...
> Hello
> I'm writing a routine to clean up a hard disk which has large numbers of
> satellite data files written onto it (approx 80MBytes/hr). We must
> remove oldest files when the disk is 80% full.
> What is the best way using Python to determine the number of bytes
> remaining on a disk?
> What's the best way under NT? under Unix?

# Windows-specific
import win32file
(sectorsPerCluster, bytesPerSector, freeClusters, totalClusters) = \
  win32file.GetDiskFreeSpace("c:\\") # or any other drive letter
percentageFull = int(long(freeClusters)*100/long(totalClusters))
bytesOfFreeSpace = sectorsPerCluster*bytesPerSector*long(freeClusters)
# etc.

The int/long calls are to avoid an OverflowError if your disk is too large
for integer math.

-M
You're smart; why haven't you learned Python yet?
http://diveintopython.org/






More information about the Python-list mailing list