Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- import re
- import sys
- import shutil
- from os.path import *
- def moveToTrash(path, trash):
- if islink(path):
- #print "unlink('%s')" % path
- os.unlink(path)
- else:
- target = join(trash, basename(path))
- index = os.getpid()
- while exists(target):
- target = "%s-%d" % (join(trash, basename(path)), index)
- index += 1
- #print "shutil.move('%s', '%s')" % (path, target)
- shutil.move(path, target)
- for item in sys.argv[1:]:
- if len(item) > 0 and item[0] == '-':
- continue
- elif not exists(item):
- continue
- target = realpath(item)
- match = re.match('/Volumes/([^/]+)/.*', target)
- if match:
- moveToTrash(item, join('/Volumes', match.group(1),
- '.Trashes', str(os.getuid())))
- else:
- moveToTrash(item, join(os.getenv('HOME'), '.Trash'))
Add Comment
Please, Sign In to add comment