[Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin
Steven D'Aprano
steve at pearwood.info
Sat Jan 3 02:50:45 CET 2015
On Fri, Jan 02, 2015 at 08:24:26AM -0500, random832 at fastmail.us wrote:
> Not having one [move to trash function] isn't acceptable either.
I'm not sure about that. Do other languages offer a move-to-trash
functionality? Say, PHP, Javascript, Java, Ruby, Boo, Go, Lua?
If Python is the odd one out that DOESN'T offer such functionality, and
all the others do, then you might have a strong case.
Otherwise, consider that the great bulk of scripts that are written in
Python don't do any file management at all, other than perhaps reading
or writing a few files. So even if Python gained this functionality, it
wouldn't have any impact on most scripts and applications.[1]
> Because what _not_ having a
> cross-platform wrapper gets you is windows and mac left behind
Really? I would expect that Windows is probably the *easiest* platform
to implement this functionality, as it has a single, standard, stable
API for moving files to trash. (Or so I am lead to believe.) You can
probably use that API via ctypes, or via pywin32.
Getting OS X right is very complicated, as Andrew has so ably explained.
In Linux and other Unixes, the situation is like OS X, only more so
since there's no one single authority. You have a choice of desktop
environments, which may or may not provide a move-to-trash API,
including no desktop environment at all. Gnome provides an API for
moving to trash, but I don't know how well it supports the freedesktop
standard; KDE supports the freedesktop standard, but I don't know if it
provides an API that can be called. XFCE has partial support.
It seems to me that "move to trash" is at least straight forward on
Windows, but tricky and complicated everywhere else.
Or, there is always the option of using a third-party module:
https://pypi.python.org/pypi/Send2Trash
[1] With one possible exception. If Andrew is correct, then the wrong
implementation of move-to-trash might effect in a bad way anyone trying
to put their app on the Apple Store, whether they use that move-to-trash
functionality or not.
--
Steve
More information about the Python-ideas
mailing list