Guest User

Untitled

a guest
Jun 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. # -------------------------------------------------------------------------
  2. # walkUp
  3. # -------------------------------------------------------------------------
  4. def walkUp(inPath, dirTag='foo'):
  5. '''
  6. Mimic something like os.walk, but walks up the directory tree
  7. Walks Up from the inPath looking for a dir with the name dirTag
  8.  
  9. inPath: the path to start in
  10. dirTag: the name of diretory above us we are looking for
  11.  
  12. returns None if the directory named dirTag is not found
  13. '''
  14. import os
  15. path = os.path.abspath(__file__)
  16. while 1:
  17. # hmmm, will this break on unix paths?
  18. # what about case sensitivity?
  19. dirBasename = os.path.basename(os.path.normcase(path))
  20. if ( dirBasename == dirTag):
  21. break
  22. path, tail = os.path.split(path)
  23. if (len(tail)==0):
  24. return None
  25. return path
  26. #--------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment