__main__.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # encoding: utf-8
  2. # Copyright 2017 Virgil Dupras
  3. # This software is licensed under the "BSD" License as described in the "LICENSE" file,
  4. # which should be included with this package. The terms are also available at
  5. # http://www.hardcoded.net/licenses/bsd_license
  6. from __future__ import print_function
  7. import sys
  8. from argparse import ArgumentParser
  9. from send2trash import send2trash
  10. if sys.version_info[0] < 3:
  11. raise RuntimeError("send2trash is only compatible with Python 3 and above (use versions <= 1.8.3 for python 2).")
  12. def main(args=None):
  13. parser = ArgumentParser(description="Tool to send files to trash")
  14. parser.add_argument("files", nargs="+")
  15. parser.add_argument("-v", "--verbose", action="store_true", help="Print deleted files")
  16. args = parser.parse_args(args)
  17. for filename in args.files:
  18. try:
  19. send2trash(filename)
  20. if args.verbose:
  21. print("Trashed «" + filename + "»")
  22. except OSError as e:
  23. print(str(e), file=sys.stderr)
  24. sys.exit(1)
  25. if __name__ == "__main__":
  26. main()