def listDirs(dir):
    for root, subFolders, files in os.walk(dir, topdown=False):
        for folder in subFolders:
            yield os.path.join(root, folder)
How to recursively loop through a file structure and rename directories in python