Load / Get Audio Files From Folder?
-
FileSystem.browseForDirectory(FileSystem.getFolder(FileSystem.Downloads), function(folder) { if (!isDefined(folder)) return; // var fileList = Engine.getSampleFilesFromDirectory( file.toString(file.FullPath), false); Console.print("Confirmed"); // Console.print(fileList); }); }; Content.getComponent("btn_LoadFolder").setControlCallback(onbtn_LoadFolderControl);
What's the proper way to get a folder in Hise, and get the audio files from it? I'd like to get the paths.
Thanks -
You can get a reference to a predefined folder using
FileSystem.getFolder(locationType)
Here's a partial list of the location types - there are more than this though which will show up in the autocomplete.
For example to get the downloads folder you would use
local downloadsFolder = FileSystem.getFolder(FileSystem.Downloads);
If you want to get a subfolder there you could then use
downloadsFolder.getChildFile("MySubfolder")
If you want to get that folder, and create it if it doesn't already exist you would replace
getChildFile
withcreateDirectory
To check if a file object is a directory you would use
myObj.isDirectory()
- check the API docs for all the available functions.To get the files within a folder you use
FileSystem.findFiles()
You might find this video helpful
-
@d-healey
To the rescue once again, thank you!
I was looking for a way to get a list of the paths of all audiofiles inside of a folder (user selects a folder, I extract the audio file locations from inside it). I'm sure that your video will likely have what I need. -
This post is deleted! -
G griffinboy marked this topic as a question
-
G griffinboy has marked this topic as solved
-
The answer:
inline function onbtn_LoadFolderControl(component, value) { if (!value) return; FileSystem.browseForDirectory(FileSystem.getFolder(FileSystem.Downloads), function(dir) { if (!isDefined(dir) || !dir.isDirectory()) return; // Print folder name Console.print(dir.toString(dir.FullPath)); // Find and print all file paths var fls = FileSystem.findFiles(dir, "*.wav", true); for (var i = 0; i < fls.length; ++i) Console.print(fls[i].toString(fls[i].FullPath)); }); }; Content.getComponent("btn_LoadFolder").setControlCallback(onbtn_LoadFolderControl);
My button is called:
btn_LoadFolder -
@griffinboy said in Load / Get Audio Files From Folder?:
for (var i = 0; i
You don't need the var here - this isn't JavaScript 🤪
-
Lol, thanks. I'm definitely still not used to it!