1

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?

2 Answers2

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
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?

  • 1
    How 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
  • 1
    Theire 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