This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Add Function for Sending File to Trash (or Recycling Bin)
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.6
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Taylor.Marks, r.david.murray, steven.daprano, vdupras
Priority: normal Keywords:

Created on 2015-05-14 03:36 by Taylor.Marks, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (4)
msg243149 - (view) Author: Taylor Marks (Taylor.Marks) Date: 2015-05-14 03:36
When you have a file that you don't think you need anymore, the proper thing to do with it is move it to the Trash (or Recycling Bin, if you're on Windows.)

The standard library, however, doesn't offer any way of doing this currently. Instead, the only thing it offers is the ability to delete files. Deleting files is a potentially dangerous operation. A novice programmer may end up carelessly delete the wrong file.

I would suggest adding in a new function which allows for cross-platform moving of files to trash. It could go into the existing shutil or os modules. Or it could get its own module (like glob).

It could be based upon (or even be exactly) this implementation:

Afterwards, the docs for os.remove and shutil.rmtree could have a warning added that suggests that instead of using such dangerous functions, it may be best for the user to use the new function.

(If this is not the place to propose additions to the standard library, please redirect me for where I should go instead. PEP 5 covers how the language should evolve, but then only has a link to
msg243173 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-05-14 10:59
Heh, dangerous is in the eye of the beholder.  I don't even have a trash bin on my system (no desktop, just X and shell windows).  

It is almost always the case that an application written in python that wants to get rid of a file *does* want to really delete it, because it is not operating on user-facing files.  It is only when the program is implementing a GUI (and very occasionally when implementing a CLI) that it might want to move something to trash instead.

I'm -1 on this proposal.  Most python programs aren't GUI programs, so I don't think any significant fraction of python programs need it, and thus that the ones that do can just include it as a dependency along with all the other dependencies they need.  (Yes, you can write a full GUI just using tkinter, but the number of GUI programs that have no non-stdlib dependencies is probably quite small.)

This is the kind of thing that would need to go to python-ideas first in any case, so I'm going to close the issue.  If you get consensus that it is a good idea on the python-ideas mailing list, you can re-open the issue.
msg243197 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2015-05-14 15:42
This has been discussed on Python-Ideas some time ago, possibly more than once. See here for one such (short) discussion:

I think that move-to-trash functionality is quite useful, I needed something like that the other day, but there are at least two trash systems on Linux (although one is quite old and may not be used in recent systems), plus Windows, OS X, Android, iOS, etc. So it isn't a trivial piece of code, and it should spend some time as a third-party module first, at least until it reaches a stable and mature state.

Since it's been more than two years since the discussion above, perhaps it is worth considering it again (assuming that the library is stable and mature). Are you interested in taking this discussion to python-ideas?
msg243220 - (view) Author: Virgil Dupras (vdupras) (Python triager) Date: 2015-05-14 22:03
For further references, there's also which is a deeper discussion and brings even more arguments against it.

Even though I'd love to have some of my code integrated into the core, arguments against its inclusion are pretty strong.
Date User Action Args
2022-04-11 14:58:16adminsetgithub: 68373
2019-10-31 14:22:49Zerosetnosy: - Zero
2016-05-09 16:28:23Zerosetnosy: + Zero
2015-05-14 22:03:15vduprassetnosy: + vdupras
messages: + msg243220
2015-05-14 15:42:55steven.dapranosetnosy: + steven.daprano
messages: + msg243197
2015-05-14 10:59:56r.david.murraysetstatus: open -> closed

versions: - Python 2.7, Python 3.4, Python 3.5
nosy: + r.david.murray

messages: + msg243173
resolution: not a bug
stage: resolved
2015-05-14 03:36:41Taylor.Markscreate