它或多或少地显示:Python中是否有一种(简单的)方法可以列出Windows系统中所有当前正在使用的驱动器号?(我的google-fu似乎让我失望了。)
3 回答

梦里花落0921
TA贡献1772条经验 获得超6个赞
如果不使用任何外部库,那么这对您很重要:
import string
from ctypes import windll
def get_drives():
drives = []
bitmask = windll.kernel32.GetLogicalDrives()
for letter in string.uppercase:
if bitmask & 1:
drives.append(letter)
bitmask >>= 1
return drives
if __name__ == '__main__':
print get_drives() # On my PC, this prints ['A', 'C', 'D', 'F', 'H']
添加回答
举报
0/150
提交
取消