使用 Python 3 弹出设备/USB (Windows 10)

问题描述 投票:0回答:1

我有一个程序可以备份到我的 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
1个回答
0
投票

是的,我自己想出来了。 代码:

import os

os.system('powershell $driveEject = New-Object -comObject Shell.Application; $driveEject.Namespace(17).ParseName("""F:""").InvokeVerb("""Eject""")')

这花了我很多时间

终于...

顺便说一句,它可能只适用于我的电脑哈哈

© www.soinside.com 2019 - 2024. All rights reserved.