# get disk/flash drive information on Windows
# using the win32 extension module from:
# http://sourceforge.net/projects/pywin32/files/
# tested on Windows XP with Python25 and Python31 by vegaseat
import win32file
import os
def get_drivestats(drive=None):
'''
drive for instance 'C'
returns total_space, free_space and drive letter
'''
# if no drive given, pick the current working directory's drive
if drive == None:
drive = os.path.splitdrive(os.getcwd())[0].rstrip(':')
sectPerCluster, bytesPerSector, freeClusters, totalClusters = \
win32file.GetDiskFreeSpace(drive + ":\\")
total_space = totalClusters*sectPerCluster*bytesPerSector
free_space = freeClusters*sectPerCluster*bytesPerSector
return total_space, free_space, drive
# use default drive (current drive)
# or specify drive for instance C --> get_drivestats('C')
total_space, free_space, drive = get_drivestats()