Last active
June 18, 2018 21:42
-
-
Save hogjonny/4ac314c403a70827b4459fb33085cfdf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ------------------------------------------------------------------------- | |
# 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