This article covers the use of the Python Send2Trash library.
Ever wondered how to delete a file(s) without that deletion being permanent? Maybe you’re in your test phase and don’t want to delete anything permanently by accident. Remember, these deletions can’t be undone in any way. This kind of situation can come up often during File handling in Python.
Python Send2Trash is a library that will help you get around this that. Install this Library first, either through the command prompt or an IDE. Refer to this guide if you don’t know how to do this. If you can execute the following command in your IDE, you have installed it successfully.
There are several things to keep in mind about this function. For one, it can delete both files and even entire directories. Secondly, you in case you are deleting a file, make sure to include it’s file extension, else it will think it’s a folder.
import send2trash send2trash.send2trash.('C:\\Users\CodersLegacy\testfile.txt')
or for deleting directories
import send2trash send2trash.send2trash.('C:\\Users\CodersLegacy\testdirectory')
This marks the end of the Python Send2Trash article. Any suggestions or contributions are more than welcome. Any relevant questions can be directed below to the comments section.