Search code examples
pythonqt4cross-platformpyqt4recycle-bin

How can I move file into Recycle Bin / trash on different platforms using PyQt4?


I would like to add the next feature to my cross-platform PyQt4 application: when user selects some file and select "remove" action on it that file will be moved to Recycle Bin folder instead of being permantly removed. I think I can find Windows-specific solution using Win32 API or something similar, but I'd like to know does similar operation could be executed on Ubuntu/Linux and MaxOSX as well via PyQt4 methods.


Solution

  • It's a good thing you're using Python, I created a library to do just that a while ago:

    http://www.hardcoded.net/articles/send-files-to-trash-on-all-platforms.htm

    On PyPI: Send2Trash

    Installation

    Using conda:

    conda install Send2Trash
    

    Using pip:

    pip install Send2Trash
    

    Usage

    Delete file or folders

    from send2trash import send2trash
    send2trash("directory")