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<<i):
if win32file.GetDriveType(drive_all[i])==3:
drives.append(drive_all[i])
return drives
def is_UDisk(drives):
UDisk=[]
for item in drives:
try :
free_bytes,total_bytes,total_free_bytes=win32file.GetDiskFreeSpaceEx(item)
if (total_bytes/1024/1024/1024)<17:
UDisk.
python检测U盘插入,获取盘符
最新推荐文章于 2024-09-30 10:17:02 发布
这篇博客介绍了如何使用Python简单检测U盘插入并获取盘符,但提到win32file模块在处理非NTFS文件系统时可能出现错误。为增加容错性,建议先判断文件系统类型。
摘要由CSDN通过智能技术生成