Skip to content

Instantly share code, notes, and snippets.

@hogjonny
Last active June 18, 2018 21:42
Show Gist options
  • Save hogjonny/4ac314c403a70827b4459fb33085cfdf to your computer and use it in GitHub Desktop.
Save hogjonny/4ac314c403a70827b4459fb33085cfdf to your computer and use it in GitHub Desktop.
# -------------------------------------------------------------------------
# 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
#--------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment