How to access a certain index of a folder in my file directory.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Major_Monkey_0720

I cannot seem to find any tutorials on what I am trying to do. I have a folder containing several snippets of audio, and I want to sort through them, and assign a certain index of the folder, to an AudioStreamPlayer. I am using godot 4.0, and cant figure out how to do this. For example, I want to do something that has the function of,


Output: [audiofile1, audiofile2, audiofile3]

If anyone could help me, that would be great.

First, what version of Godot are you using? That’ll be important for a useful answer.

It’s not entirely clear what you’re trying to do from your example. Do you just have a single, flat folder of audio files or are there multiple sub-folders that contain such files? From your description, I assume just a single, flat folder. But, if that’s the case, I don’t understand your example.

Assuming you’re just storing the files in an array, then I’d expect this:


To print:


(based on your original post).

Also, note that get_index() isn’t a valid function for any collection that I’m aware of (which is why I’m using array access notation above)…

If any of that is remotely on-track, what exactly are you having trouble with?

  • Accessing the files on disk?
  • Loading the files in to a collection (Array above)?
  • Accessing the array’s contents?
  • Something else?

jgodfrey | 2023-04-10 18:25

I was not implying that get_index() was a function, I just wanted to give an example of the type of function I wanted to achieve. I’m hoping to access through code, strings containing a path to the audiofile located a under a specific folder, and was wondering how I can reference that. I am using Godot 4.0 stable release btw.

Major_Monkey_0720 | 2023-04-11 01:59

Again, are you just trying to manage a single, flat folder of audio files or can the folder also contains sub-folders that also contain audio files?

jgodfrey | 2023-04-11 13:27