Skip to content

Instantly share code, notes, and snippets.

@fredrikaverpil
Created March 25, 2014 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredrikaverpil/9761312 to your computer and use it in GitHub Desktop.
Save fredrikaverpil/9761312 to your computer and use it in GitHub Desktop.
Traverse backwards folderpath to find a folder #nuke
def traverseBackwardsAndFindFolder( startPath, searchForFolder ):
# Usage example: traverseBackwardsAndFindFolder( nuke.root().name(), 'render' )
returnPath = ''
for i in range(len(startPath.split('/'))):
startPath = startPath[:startPath.rfind('/')]
# Check if it exists
if (os.path.isdir(startPath + '/' + searchForFolder)):
returnPath = startPath + '/' + searchForFolder
# If not found
if returnPath == '':
print('Error: Cannot find folder + \"' + searchForFolder + '\".')
return returnPath
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment