尝试制作简单的python脚本来删除Mac上的message(对于iMessage)目录。路径为usrs / library / messages(我要删除邮件文件夹)
#!/usr/bin/python
import subprocess, os, shutil`
import send2trash as trash
subprocess.call(['osascript', '-e', 'tell application "Messages" to quit'])
shutil.rmtree('Usr/Library/Messages')
#trash.send2trash(os.path.join("Usr/Library/Messages", "chat.db"))
warning = input("Do you want to restart computer?(y/n)")
if warning == "n":
exit()
else:
os.system("shutdown /r /t 1")`import subprocess, os, shutil
在过去的几个小时中,我对此进行了深入的研究(我对编程还很陌生),感到很困惑。显示的代码只是删除目录的最新尝试。我也有send2trash模块,我无法弄清楚,自然界中有很多类似的问题,但是没有一个问题对我有足够的帮助。目前,我的代码与此消息相关的错误:
Traceback (most recent call last):
File "/Users/me/PycharmProjects/plistscript/script.py", line 8, in <module>
shutil.rmtree('Usr/Library/Messages')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py", line 494, in rmtree
return _rmtree_unsafe(path, onerror)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py", line 376, in _rmtree_unsafe
onerror(os.listdir, path, sys.exc_info())
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py", line 374, in _rmtree_unsafe
names = os.listdir(path)
FileNotFoundError: [Errno 2] No such file or directory: 'Usr/Library/Messages'
这是我在这里的第一个问题,所以请放心:)
答案 0 :(得分:0)
您可能要删除/Users/Library/Messages
或/usr/Library/Messages
,请检查代码中的目录是否存在