Recursion is your friend!
By calling the function from itself again you can traverse through an unknown level of subfolders.
Here is a little example to build a list of all clips. I’ve modified some names slightly to stick to some Autodesk terminology (e.g. clips instead of entries etc.) to make things more understandable. Hope this helps.
import flame
clips = []
def build_clip_list(current_folder):
"""recursive search for entries"""
global clips
for folder in current_folder:
if has_subfolder(folder):
build_clip_list(folder.folders)
for clip in folder.clips:
clips.append(clip)
def collect_clips():
"""function that returns all clips as a list"""
global clips
clips = []
for library in flame.project.current_project.current_workspace.libraries:
build_clip_list(library.folders)
return clips
def has_subfolder(folder):
"""check if the given folder has any subfolders"""
if len(folder.folders) == 0:
return False
else:
return True
print collect_clips()
This could be improved by running set on the list at the end or implementing another mechanism to avoid duplicate entries in the list.