1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2024-12-03 19:59:02 +00:00
send2trash/send2trash/plat_other.py
2010-04-06 18:55:30 +02:00

22 lines
627 B
Python

from __future__ import unicode_literals
import sys
import os
import os.path as op
TRASH_PATH = op.expanduser('~/.Trash')
# XXX Make this work on external volumes
def send2trash(path):
if not isinstance(path, unicode):
path = unicode(path, sys.getfilesystemencoding())
filename = op.basename(path)
destpath = op.join(TRASH_PATH, filename)
counter = 0
while op.exists(destpath):
counter += 1
base_name, ext = op.splitext(filename)
new_filename = '{0} {1}{2}'.format(base_name, counter, ext)
destpath = op.join(TRASH_PATH, new_filename)
os.rename(path, destpath)