mirror of
https://github.com/arsenetar/send2trash.git
synced 2024-12-06 20:59:03 +00:00
Andrew Senetar
d078554052
* Initial IFileOperation for Windows - Try using IFileOperation instead of SHFileOperation - Use pywin32 to accomplish this - Implement fallback when pywin32 not available - Handles paths like `C:\` just fine bu the `\\?\` paths in the test cause issue - Add batching for IFileOperation version (performance) - Minor formatting applied by editor * Fix issue with paths starting with \\?\ - Strip these characters off if present just like old implementation * Add windows version check, legacy list support - Add check for windows version for IFileOperation - Add list support to legacy version - Remove some debugging code - Fix bug in path converson Not sure if there is a better way to layout this file * Split plat_win into legacy and modern * Update other platforms for list support Formatter also ran on these so some other minor changes. * Add unit tests for multi-file calls
24 lines
873 B
Python
24 lines
873 B
Python
# Copyright 2017 Virgil Dupras
|
|
|
|
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
|
|
# which should be included with this package. The terms are also available at
|
|
# http://www.hardcoded.net/licenses/bsd_license
|
|
|
|
from gi.repository import GObject, Gio
|
|
from .exceptions import TrashPermissionError
|
|
|
|
|
|
def send2trash(paths):
|
|
if not isinstance(paths, list):
|
|
paths = [paths]
|
|
for path in paths:
|
|
try:
|
|
f = Gio.File.new_for_path(path)
|
|
f.trash(cancellable=None)
|
|
except GObject.GError as e:
|
|
if e.code == Gio.IOErrorEnum.NOT_SUPPORTED:
|
|
# We get here if we can't create a trash directory on the same
|
|
# device. I don't know if other errors can result in NOT_SUPPORTED.
|
|
raise TrashPermissionError("")
|
|
raise OSError(e.message)
|