lll.py 748 B

123456789101112131415161718192021222324252627
  1. #! /usr/bin/env python3
  2. # Find symbolic links and show where they point to.
  3. # Arguments are directories to search; default is current directory.
  4. # No recursion.
  5. # (This is a totally different program from "findsymlinks.py"!)
  6. import sys, os
  7. def lll(dirname):
  8. for name in os.listdir(dirname):
  9. if name not in (os.curdir, os.pardir):
  10. full = os.path.join(dirname, name)
  11. if os.path.islink(full):
  12. print(name, '->', os.readlink(full))
  13. def main(args):
  14. if not args: args = [os.curdir]
  15. first = 1
  16. for arg in args:
  17. if len(args) > 1:
  18. if not first: print()
  19. first = 0
  20. print(arg + ':')
  21. lll(arg)
  22. if __name__ == '__main__':
  23. main(sys.argv[1:])