check_path.py 584 B

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