check_path.py 623 B

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python
  2. from __future__ import print_function
  3. import os
  4. import sys
  5. def check_path(argv):
  6. if len(argv) < 3:
  7. print("Wrong number of args")
  8. return 1
  9. type = argv[1]
  10. paths = argv[2:]
  11. exit_code = 0
  12. if type == 'dir':
  13. for idx, dir in enumerate(paths):
  14. print(os.path.isdir(dir))
  15. elif type == 'file':
  16. for idx, file in enumerate(paths):
  17. print(os.path.isfile(file))
  18. else:
  19. print("Unrecognised type {}".format(type))
  20. exit_code = 1
  21. return exit_code
  22. if __name__ == '__main__':
  23. sys.exit (check_path (sys.argv))