[英]Eject Device/USB using Python 3 (Windows 10)
我有一個程序可以備份到我的 USB,但為了更容易,我想讓它在完成后自動彈出。
(做了“路徑”,所以我不公開個人文件)代碼:
from shutil import copytree as ct
from shutil import copyfile as cf
from shutil import make_archive as arc
from shutil import rmtree as rm
from time import sleep as wait
f_drive = r'F:\BACKUP\stuff'
path_to_user = r'path'
another_path = r"path"
a_path = r'path'
def backup():
ct(r'path', r'path')
ct(r'path', r"F:\BACKUP\stuff\path")
ct(r'path', r"path")
ct(r'D:\path', r'path')
print("Starting backup...")
print("This process is automatic. This should not take any longer than 2 minutes...")
backup()
print()
print("Backup complete!")
print("Archiving folder...")
arc(r"F:\BACKUP", "zip", r'F:\BACKUP')
rm(r'F:\BACKUP')
print("Program will close in 10 seconds.")
wait(10)
(我知道還有其他問題,但我認為這是唯一一個 python usb 彈出)
是的,我自己想通了。 代碼:
import os
os.system('powershell $driveEject = New-Object -comObject Shell.Application; $driveEject.Namespace(17).ParseName("""F:""").InvokeVerb("""Eject""")')
這花了我很多時間
最后...
順便說一句,它可能只適用於我的電腦哈哈
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.