Array of audio files working in editor but not when exported

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

So I have a AudioStreamPlayer, that has script that iterates through a folder and pulls all the wav files and stores them in an array and then a method to play one of them at random and another to skip to the next song. When I do this in the editor it works with no issues or errors, but as soon as I export it to a runnable windows exe it fails to retrieve any of the files and shows a error of
Invalid get index ‘0’ (on base: ‘Array’).
At: res://World/MusicPlayer.gdc:32

this is the code below im using

extends AudioStreamPlayer

var music_list = []
func ready():

func input(event):
    if event.isactionpressed("skipsong"):

func getallmusic():
    var dir ="res://Assets/Music/")

    while true:
        var file = dir.get_next()
        if file == "":
            #no more files
        elif not file.begins_with(".") && !file.ends_with(".import"):
            music_list.append(load("res://Assets/Music/" + file))

     func picksong():
    var listlen = musiclist.size()
    var i = randi() % (listlen - 1)
    stream = musiclist[i]

func onMusicPlayerfinished():
:bust_in_silhouette: Reply From: exuin

The problem is that you cannot find imported files like your music in an exported project. They are not exported. What is exported is the imported files in the .import folder. However, the .import files are still there. You will be able to find the .import files with the directory. So instead of excluding them from the search, only look for them. Then, remove the “.import” from the end and load the file.

thanks that solved it!

elif not file.begins_with(".") && file.ends_with(".import"):
		file = file.split(".import")
		music_list.append(load("res://Assets/Music/" + file[0]))

there is my edit to my code case anyone else runs into this issue

sir306 | 2021-07-07 11:18