0
我還沒有用過很多python,但我想創建一個在後臺運行的連續腳本,並尋找插入的新驅動器。我想要腳本能夠從驅動器獲取所有文件並將它們存儲在我指定的其他位置。這是有人可以幫助我的東西,還是我應該看看其他地方?謝謝!通過python讀取和複製讀卡器中的文件
我還沒有用過很多python,但我想創建一個在後臺運行的連續腳本,並尋找插入的新驅動器。我想要腳本能夠從驅動器獲取所有文件並將它們存儲在我指定的其他位置。這是有人可以幫助我的東西,還是我應該看看其他地方?謝謝!通過python讀取和複製讀卡器中的文件
這可能讓你開始:
import subprocess
import time
def get_drives():
"""Return a list of disk drives"""
output = subprocess.check_output("fsutil fsinfo drives")
return output[output.find(b":")+1:].decode("utf-8").split()
sleep_interval = 60 # seconds
while True:
# get a list of the current drives
drives = get_drives()
try:
time.sleep(sleep_interval)
# check for new drives
new_drives = get_drives()
for drive in new_drives:
if drive not in drives:
print(drive, "detected")
# do more stuff here
# update stored drives so we can detect removal & reinsertion
drives = new_drives
except KeyboardInterrupt:
print("Exiting")
break
對於你的測試,你可能會想與睡眠間隔設置爲一秒鐘左右。 按Ctrl+C
退出。
運行示例:
J:\>python drive_check.py
D:\ detected
Exiting
我會嘗試了這一點。太感謝了! – DustySucks420