Created
August 13, 2010 13:21
-
-
Save bussiere/522867 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Return disk space | |
import string | |
import win32api | |
import win32file | |
def PrintSpaceReport(drive): | |
sectorsPerCluster, bytesPerSector, numFreeClusters, totalNumClusters = win32file.GetDiskFreeSpace(drive + ":\\") | |
sectorsPerCluster = long(sectorsPerCluster) | |
bytesPerSector = long(bytesPerSector) | |
numFreeClusters = long(numFreeClusters) | |
totalNumClusters = long(totalNumClusters) | |
rapport = "\n" | |
rapport += "Drive: %s:\\\n"% str(drive) | |
rapport += "FreeSpace: %s MB\n"% str((numFreeClusters * sectorsPerCluster *bytesPerSector) / (1024 * 1024)) | |
rapport += "UsedSpace: %s MB\n"% str(((totalNumClusters - numFreeClusters ) * sectorsPerCluster * bytesPerSector) / (1024 * 1024)) | |
rapport += "TotalSpace: %s MB\n"%str((totalNumClusters * sectorsPerCluster *bytesPerSector) / (1024 * 1024)) | |
return rapport | |
def main(): | |
AvailableDrives = [] | |
for i in string.split(win32api.GetLogicalDriveStrings(), '\000'): | |
if win32file.GetDriveType(i) == 3: # we only need fixed drives (no CD drives) | |
AvailableDrives.append(i[:-2]) | |
DriveInfo = [] | |
rapport = "" | |
for drive in AvailableDrives: | |
try : | |
rapport += str(PrintSpaceReport(drive)) | |
except : | |
pass | |
return rapport | |
print main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment