I've been looking for this info for awhile, and I have a number of ways to retrieve a list of local drives under Windows. Here are two examples:
print win32api.GetLogicalDriveStrings().split("\x00")
and
def getDriveLetters(self):
self.drvs = []
n_drives = win32api.GetLogicalDrives()
for i in range(0,25): #check all drive letters
j = 2**i # bitmask for each letter
if n_drives & j > 0:
self.drvs.append(chr(65+i)+":/")
print self.drvs
What I can't seem to find is a way to separate the floppies (A:), usb drives (G:), CD drives (E:), and network drives (P:) from the Local hard drives (C:, D:)
If they all were assigned the same letters it would be easy, but I'm writing this script to monitor local hard disk space across a network of computers with different configurations.
Any help would be appreciated! Thanks.
You can try the win32 GetDriveType function.
import win32file
>>> win32file.GetDriveType("C:/") == win32file.DRIVE_FIXED ##hardrive
True
>>> win32file.GetDriveType("Z:/") == win32file.DRIVE_FIXED ##network
False
>>> win32file.GetDriveType("D:/") == win32file.DRIVE_FIXED ##cd-rom
False
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With