import time
from shutil import copytree
from psutil import disk_partitions
copyFlag = False
def usbCopy(driver):
try:
path = r'D:\usb-' + time.strftime("%Y%m%d%H%M%S", time.localtime())
print(f'开始复制,复制路径: {path}')
copytree(driver, path)
print('复制结束')
return True
except Exception as e:
print(e)
return False
while True:
# 设置休眠时间
time.sleep(5)
# 检测所有的驱动器
for item in disk_partitions():
print(f'{item.device} {item.opts}')
if 'removable' in item.opts:
print('发现usb驱动:', item.device)
copyFlag = usbCopy(item.device)
if copyFlag == True:
break
标签:usb,pyhon,item,复制,time,print,import,监听
From: https://www.cnblogs.com/wstong2052/p/17603743.html