I have a more general question about the os.remove()
-function.
When I use it to delete a file, does Python delete it entirely from the computer or does Python move it to another folder similar to the trash on mac?
Asked
Active
Viewed 868 times
1

Python_Question
- 45
- 5
2 Answers
0
os.remove()
doesn't send things to Trash. It just deletes them.
You can check it yourself very easily:
import os
file = 'file.txt'
location = "/home/User/Documents"
path = os.path.join(location, file)
os.remove(path)
print("%s has been removed successfully" % file)

Julian
- 172
- 1
- 10
-
How do you know that? – Kelly Bundy Aug 20 '21 at 12:49
-
I checked it by writing eight lines of code – Julian Aug 20 '21 at 12:54
0
os.remove
doesn't send things to Trash. It just deletes them.
Here you go for os.remove
docs: https://docs.python.org/3/library/os.html#os.remove
Also i notice similar post on stackoverflow: How to permanently delete a file in python 3 and higher?
-
1How do you know that? That doc doesn't say what "delete" means. If I for example "delete" a file in Windows File Explorer by right-clicking it and clicking "Delete", it *does* go to the Recycle Bin. – Kelly Bundy Aug 20 '21 at 12:50
-
1Theire is alreay accepted answer, here you go: https://stackoverflow.com/questions/57130303/how-to-permanently-delete-a-file-in-python-3-and-higher – Aug 20 '21 at 12:51