Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # Search for files upward from current working directory
  4.  
  5. import os
  6. import stat
  7. import sys
  8.  
  9.  
  10. def upfind(file):
  11. dir = os.getcwd()
  12. fullpath = os.path.join(dir, file)
  13.  
  14. while not os.path.isfile(fullpath):
  15. if dir == "/":
  16. break
  17. dir = os.path.dirname(dir)
  18. fullpath = os.path.join(dir, file)
  19.  
  20. return fullpath if os.path.isfile(fullpath) else None
  21.  
  22. if __name__ == "__main__":
  23. for path in filter(None, [upfind(arg) for arg in sys.argv[1:]]):
  24. print path
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement