# Mimic os.walk

**URL:** <https://forum.logik.tv/t/mimic-os-walk/3631>\
**Category:** Python\
**Created:** [August 11, 2021, 7:54am UTC](https://forum.logik.tv/t/mimic-os-walk/3631 "2021-08-11T07:54:16Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![claussteinmassl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.logik.tv/claussteinmassl/32/1922_2.png) [@claussteinmassl](https://forum.logik.tv/u/claussteinmassl)\
**Post date:** [August 11, 2021, 11:50am UTC](https://forum.logik.tv/t/mimic-os-walk/3631/2 "2021-08-11T11:50:49Z")

</div>

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. 🙂

```auto
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.

---

_[View the full topic](https://forum.logik.tv/t/mimic-os-walk/3631)._
