[英]in Python, how to separate Local Hard Drives from Network and Floppy in Windows?
[英]How to get a list of local drives without SUBST'ituted ones in Python / Windows?
我正在寻找一种在Windows计算机上获取所有本地驱动器的方法,到目前为止,我尝试了两种选择
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)
这两种方式(几乎)都可以正常工作,我得到了以下驱动器列表:
A: 1 // Removable
C: 2 // Fixed
D: 2
E: 2
G: 2 // Fixed (??? SUBST'ed drive)
I: 4 // Cd-Rom
X: 3 // Network
但是G:驱动器是SUBST的驱动器(例如:用SUBST G:C:\\ TEST创建),我找不到将其与“真实”本地驱动器区分开的方法。
有任何想法吗?
TIA,巴勃罗
Google告诉我,如果您尝试获取SUBST版驱动器的GUID,它将失败:
>>> import win32file
>>> win32file.GetVolumeNameForVolumeMountPoint("C:\\")
'\\\\?\\Volume{50c800a9-c62e-11df-b5bb-806e6f6e6963}\\'
>>> win32file.GetVolumeNameForVolumeMountPoint("K:\\")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pywintypes.error: (87, 'GetVolumeNameForVolumeMountPoint',
'The parameter is incorrect.')
这似乎可行,但可能不可靠。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.