Determining disk space
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...
> 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?
(sectorsPerCluster, bytesPerSector, freeClusters, totalClusters) = \
win32file.GetDiskFreeSpace("c:\\") # or any other drive letter
percentageFull = int(long(freeClusters)*100/long(totalClusters))
bytesOfFreeSpace = sectorsPerCluster*bytesPerSector*long(freeClusters)
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