[Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin

Andrew Barnert abarnert at yahoo.com
Mon Dec 29 19:58:31 CET 2014


On Dec 29, 2014, at 18:53, Antoine Pitrou <solipsis at pitrou.net> wrote:

> On Mon, 29 Dec 2014 18:54:46 +0200
> Ram Rachum <ram at rachum.com> wrote:
>> Hi guys,
>> 
>> I want to have a method of `pathlib.Path` that would send a file to the
>> recycle bin. (i.e. soft delete.)
>> 
>> What do you think about adding this?
>> 
>> I see there's a PyPI package `Send2Trash` that does this, but it would be
>> nice if this was in the standard library.
> 
> I think the corresponding low-level function to the os module would be
> a good start (the hard part is probably to write the cross-platform
> code, anyway).

There isn't really a low-level function for it on any platform but maybe Windows, except rename, which is already there.

On OS X, unless you want to use higher-level CoreFoundation APIs that require a runloop, you just look up the name of the trash directory (which I believe is theoretically localized but actually always ~/.Trash on the drive with your user directory, $mnt/.Trash otherwise) and call rename. On Linux, and some other *nix platforms, you assume XDG directory layout and call rename. On other platforms, I don't know if there even is a way to do it.

And I don't know what the right thing to do on OS X would be for a file on a different filesystem than the user's home that doesn't have its own .Trash or is mounted read-only or no-trash. Finder gives you a popup in each of those cases asking if you want to delete it immediately because it can't be trashed. And similarly for Linux, but the details are different (especially since you might not even have a home trash).

I'd guess Send2Trash is a good place to at least start, but if this is going in the stdlib someone needs to make sure it meets Apple HIG rules and XDG standards.

> 
> Regards
> 
> Antoine.
> 
> 
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list