mirror of
https://github.com/arsenetar/send2trash.git
synced 2024-12-21 10:59:03 +00:00
Added the plat_other module (for Linux).
This commit is contained in:
parent
8a1dff2947
commit
6856e49f2d
@ -5,4 +5,4 @@ if sys.platform == 'darwin':
|
||||
elif sys.platform == 'win32':
|
||||
from plat_win import send2trash
|
||||
else:
|
||||
print "Unsupported platform"
|
||||
from plat_other import send2trash
|
||||
|
21
send2trash/plat_other.py
Normal file
21
send2trash/plat_other.py
Normal file
@ -0,0 +1,21 @@
|
||||
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)
|
Loading…
Reference in New Issue
Block a user