Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -------------------------------------------------------------------------
- # walkUp
- # -------------------------------------------------------------------------
- def walkUp(inPath, dirTag='foo'):
- '''
- Mimic something like os.walk, but walks up the directory tree
- Walks Up from the inPath looking for a dir with the name dirTag
- inPath: the path to start in
- dirTag: the name of diretory above us we are looking for
- returns None if the directory named dirTag is not found
- '''
- import os
- path = os.path.abspath(__file__)
- while 1:
- # hmmm, will this break on unix paths?
- # what about case sensitivity?
- dirBasename = os.path.basename(os.path.normcase(path))
- if ( dirBasename == dirTag):
- break
- path, tail = os.path.split(path)
- if (len(tail)==0):
- return None
- return path
- #--------------------------------------------------------------------------
Add Comment
Please, Sign In to add comment