Search code examples
pythonfileerase

Python securely remove file


How can I securely remove a file using python? The function os.remove(path) only removes the directory entry, but I want to securely remove the file, similar to the apple feature called "Secure Empty Trash" that randomly overwrites the file.

What function securely removes a file using this method?


Solution

  • You can use srm to securely remove files. You can use Python's os.system() function to call srm.