python检测U盘插入,获取盘符

import win32file

def getdrives():
    drives=[]
    sign=win32file.GetLogicalDrives()
    drive_all=["A:\\","B:\\","C:\\","D:\\","E:\\","F:\\","G:\\","H:\\","I:\\",
                "J:\\","K:\\","L:\\","M:\\","N:\\","O:\\","P:\\","Q:\\","R:\\",
                "S:\\","T:\\","U:\\","V:\\","W:\\","X:\\","Y:\\","Z:\\"]
    for i in range(25):
        if (sign&1<

U盘检测这部分,方法比较弱智,本来考虑监控进程U盘插入过程中windows的识别进程的,太麻烦了,仅供参考

问题:

win32file果然只能读取NTFS文件系统的硬盘

所以电脑上有多个系统,有windows不支持的文件系统时,win32file那里会报错

可以考虑先获取文件系统类别,增大容错性

你可能感兴趣的:(python)