Trying to make simple python script to delete the messages (for iMessage) directory on Mac. Path is usrs/library/messages (I want to delete messages folder)
#!/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
I have thoroughly researched this for the past few hours (I'm pretty new to programming) and am sooo stumped. The code shown is only the latest attempt to delete a directory. I also have the send2trash module that I couldn't figure out lol there were plenty of questions similar on stack in nature but none that helped me enough to crack this. Currently my code errors with this message:
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'
This is my first question on here so go easy on me :)