2021-04-14 03:36:10 +00:00
|
|
|
# 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 Foundation import NSFileManager, NSURL
|
|
|
|
from .compat import text_type
|
2021-08-08 02:48:10 +00:00
|
|
|
from .util import preprocess_paths
|
2021-04-14 03:36:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def check_op_result(op_result):
|
|
|
|
# First value will be false on failure
|
|
|
|
if not op_result[0]:
|
|
|
|
# Error is in third value, localized failure reason matchs ctypes version
|
|
|
|
raise OSError(op_result[2].localizedFailureReason())
|
|
|
|
|
|
|
|
|
|
|
|
def send2trash(paths):
|
2021-08-08 02:48:10 +00:00
|
|
|
paths = preprocess_paths(paths)
|
2021-08-17 23:58:11 +00:00
|
|
|
paths = [path.decode("utf-8") if not isinstance(path, text_type) else path for path in paths]
|
2021-04-14 03:36:10 +00:00
|
|
|
for path in paths:
|
|
|
|
file_url = NSURL.fileURLWithPath_(path)
|
|
|
|
fm = NSFileManager.defaultManager()
|
|
|
|
op_result = fm.trashItemAtURL_resultingItemURL_error_(file_url, None, None)
|
|
|
|
check_op_result(op_result)
|