Determining disk space

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

"Gary Quinn" <gary at> wrote in message
news:3A9B2ABA.AFFC65EC at
> 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.

You're smart; why haven't you learned Python yet?

More information about the Python-list mailing list