| 1 |
================================================== |
| 2 |
Send2Trash -- Send files to trash on all platforms |
| 3 |
================================================== |
| 4 |
|
| 5 |
Send2Trash is a small package that sends files to the Trash (or Recycle Bin) *natively* and on |
| 6 |
*all platforms*. On OS X, it uses native ``FSMoveObjectToTrashSync`` Cocoa calls or can use pyobjc |
| 7 |
with NSFileManager. On Windows, it uses native ``IFileOperation`` call if on Vista or newer and |
| 8 |
pywin32 is installed or falls back to ``SHFileOperation`` calls. On other platforms, if `PyGObject`_ |
| 9 |
and `GIO`_ are available, it will use this. Otherwise, it will fallback to its own implementation of |
| 10 |
the `trash specifications from freedesktop.org`_. |
| 11 |
|
| 12 |
``ctypes`` is used to access native libraries, so no compilation is necessary. |
| 13 |
|
| 14 |
Send2Trash supports Python 2.7 and up (Python 3 is supported). |
| 15 |
|
| 16 |
Status: Additional Help Welcome |
| 17 |
------------------------------- |
| 18 |
|
| 19 |
Additional help is welcome for supporting this package. Specifically help with the OSX and Linux |
| 20 |
issues and fixes would be most appreciated. |
| 21 |
|
| 22 |
Installation |
| 23 |
------------ |
| 24 |
|
| 25 |
You can download it with pip: |
| 26 |
|
| 27 |
python -m pip install -U send2trash |
| 28 |
|
| 29 |
To install with pywin32 or pyobjc required specify the extra `nativeLib`: |
| 30 |
|
| 31 |
python -m pip install -U send2trash[nativeLib] |
| 32 |
|
| 33 |
or you can download the source from http://github.com/arsenetar/send2trash and install it with:: |
| 34 |
|
| 35 |
>>> python setup.py install |
| 36 |
|
| 37 |
Usage |
| 38 |
----- |
| 39 |
|
| 40 |
>>> from send2trash import send2trash |
| 41 |
>>> send2trash('some_file') |
| 42 |
>>> send2trash(['some_file1', 'some_file2']) |
| 43 |
|
| 44 |
On Freedesktop platforms (Linux, BSD, etc.), you may not be able to efficiently |
| 45 |
trash some files. In these cases, an exception ``send2trash.TrashPermissionError`` |
| 46 |
is raised, so that the application can handle this case. This inherits from |
| 47 |
``PermissionError`` (``OSError`` on Python 2). Specifically, this affects |
| 48 |
files on a different device to the user's home directory, where the root of the |
| 49 |
device does not have a ``.Trash`` directory, and we don't have permission to |
| 50 |
create a ``.Trash-$UID`` directory. |
| 51 |
|
| 52 |
For any other problem, ``OSError`` is raised. |
| 53 |
|
| 54 |
.. _PyGObject: https://wiki.gnome.org/PyGObject |
| 55 |
.. _GIO: https://developer.gnome.org/gio/ |
| 56 |
.. _trash specifications from freedesktop.org: http://freedesktop.org/wiki/Specifications/trash-spec/ |