I’m looking for a way to get all the local drives on a Windows machine,
So far, I tried with two options
1)
# Win32Com
from win32com.client import Dispatch
import sys
fso = Dispatch('Scripting.FileSystemObject')
for drive in fso.Drives:
print drive, drive.DriveType
2)
# win32api
import win32api
import win32file
drives = (drive for drive in win32api.GetLogicalDriveStrings().split("\000") if drive)
for drive in drives:
print drive, win32file.GetDriveType(drive)
This two ways works (almost) fine, I get my drive list such as:
A: 1 // Removable
C: 2 // Fixed
D: 2
E: 2
G: 2 // Fixed (??? SUBST'ed drive)
I: 4 // Cd-Rom
X: 3 // Network
but the G: drive is a SUBST’ed drive (eg: created with SUBST G: C:\TEST),
and I cannot find the way to differentiate it from a “real” local drive.
Any ideas?
TIA,
Pablo
Google tells me that if you try and fetch a GUID for a SUBST-ed drive it will fail:
This seems to work but may not be reliable.