How to prevent "load(path)" from loading .import files?

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

I am trying to import audio files from a “res://” directory, but load() is also loading in the .import files along with the audio. See here:

E 0:00:00.626   _load: No loader found for resource: res://audio/sfx/player/footsteps/HardFloor/Footstep_HardFloor_Hard_Variation1.wav.import.
  <C++ Error>   Method failed. Returning: RES()
  <C++ Source>  core/io/resource_loader.cpp:286 @ _load()
  <Stack Trace> @ GetSFXArrays()
       @ _ready()

There are 25 errors like this.

Here is my code for gathering the files:

func GetSFXArrays(pathHF, pathS):
	var HardFloorSFX = []
	var HF_SoundDirectory =
	HF_SoundDirectory .open(pathHF)
	var sfxHF = HF_SoundDirectory.get_next()
	while sfxHF != "":
		HardFloorSFX.append(load(pathHF + sfxHF))
		sfxHF = HF_SoundDirectory.get_next()
	HFSoundReturned = HardFloorSFX
:bust_in_silhouette: Reply From: exuin

So here’s the thing: imported files can no longer be found on their original locations after export. They’re all in the .import folder. So you’ll need to look for the .import files, which are still in their original location. However, you can’t load them. So what you need to do is to remove the .import from the file name.

file_name = file_name.replace(".import", "")

Now, just load the new file name. Even though the original file is not there anymore, the ResourceLoader can still load it from the name.