Guest User

Untitled

a guest
May 26th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4. import re
  5. import sys
  6. import shutil
  7.  
  8. from os.path import *
  9.  
  10. def moveToTrash(path, trash):
  11. if islink(path):
  12. #print "unlink('%s')" % path
  13. os.unlink(path)
  14. else:
  15. target = join(trash, basename(path))
  16. index = os.getpid()
  17. while exists(target):
  18. target = "%s-%d" % (join(trash, basename(path)), index)
  19. index += 1
  20.  
  21. #print "shutil.move('%s', '%s')" % (path, target)
  22. shutil.move(path, target)
  23.  
  24. for item in sys.argv[1:]:
  25. if len(item) > 0 and item[0] == '-':
  26. continue
  27. elif not exists(item):
  28. continue
  29.  
  30. target = realpath(item)
  31. match = re.match('/Volumes/([^/]+)/.*', target)
  32. if match:
  33. moveToTrash(item, join('/Volumes', match.group(1),
  34. '.Trashes', str(os.getuid())))
  35. else:
  36. moveToTrash(item, join(os.getenv('HOME'), '.Trash'))
Add Comment
Please, Sign In to add comment