# Recursively read (audio) files from directories

**URL:** <https://support.prodi.gy/t/recursively-read-audio-files-from-directories/6393>\
**Category:** Uncategorized\
**Tags:** audio\
**Created:** [February 27, 2023, 9:21am UTC](https://support.prodi.gy/t/recursively-read-audio-files-from-directories/6393 "2023-02-27T09:21:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luisa\_mai](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/luisa_mai/32/2539_2.png) [@luisa\_mai](https://support.prodi.gy/u/luisa_mai)\
**Post date:** [February 27, 2023, 9:21am UTC](https://support.prodi.gy/t/recursively-read-audio-files-from-directories/6393/1 "2023-02-27T09:21:50Z")

</div>

Hello,

I am working with the `AudioServer` media loader, and am looking for a way to load files from a directory recursively. My setup closely follows [this example](https://prodi.gy/docs/audio-video#classify), but has the audio files stored in sub directories.  
Is there any way to load the files from there, recursively (via their file extension)?

Generally, I found this function to be important, so might be a good feature anyway!

---

<div class="post-metadata">

**Author:** ![luisa\_mai](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/luisa_mai/32/2539_2.png) [@luisa\_mai](https://support.prodi.gy/u/luisa_mai)\
**Post date:** [February 27, 2023, 9:36am UTC](https://support.prodi.gy/t/recursively-read-audio-files-from-directories/6393/2 "2023-02-27T09:36:58Z")

</div>

Answering my own question:  
The solution lies in using a combination of plain lists and the `fetch_media` preprocessor:

```python
    def get_stream_custom():
        files = [{"audio": file_path, "meta": {"file": file_path}} for file_path in
                 glob.glob(os.path.join(source, "**/*.flac"), recursive=True)]
        stream = fetch_media(files, ["audio"])
        for eg in stream:
            eg["options"] = [
                {"id": "CAR", "text": "car"},
                {"id": "PLANE", "text": "PLANE"},
                {"id": "OTHER", "text": "Other / Unclear"}
            ]
            yield eg

```

This function replaces the `get_stream()` function in the example I linked.

---

<div class="post-metadata">

**Author:** ![koaning](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/koaning/32/230_2.png) [@koaning](https://support.prodi.gy/u/koaning)\
**Post date:** [February 27, 2023, 10:04am UTC](https://support.prodi.gy/t/recursively-read-audio-files-from-directories/6393/3 "2023-02-27T10:04:41Z")

</div>

Happy to hear you found a solution!
