Created
March 25, 2014 12:58
-
-
Save fredrikaverpil/9761312 to your computer and use it in GitHub Desktop.
Traverse backwards folderpath to find a folder #nuke
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
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