Get list of midi files
-
@d-healey Thank you so much!
//hold file list var fileList = []; const var Browse = Content.getComponent("Browse"); inline function onBrowseControl(component, value) { if(value) //if button clicked { //open file broswer FileSystem.browseForDirectory("", function(dir) { //push midi list into array fileList.push(FileSystem.findFiles(dir, "*.mid", false)); }); } }; Content.getComponent("Browse").setControlCallback(onBrowseControl); -
And one last tweak. The above code puts an array of files inside of an array...
This will just populate the array with files://hold file list var fileList = []; const var Browse = Content.getComponent("Browse"); inline function onBrowseControl(component, value) { if(value) //if button clicked { //open file broswer FileSystem.browseForDirectory("", function(dir) { //push midi list into array local midiFiles = FileSystem.findFiles(dir, "*.mid", false); for(m in midiFiles) { fileList.push(m); } }); } }; Content.getComponent("Browse").setControlCallback(onBrowseControl); -
@dustbro Then why not just:
fileList = FileSystem.findFiles(dir, "*.mid", false);Or if you want to keep a local var (if ever you have a good reason)
fileList = midiFiles; -
@ustk said in Get list of midi files:
@dustbro Then why not just:
fileList = FileSystem.findFiles(dir, "*.mid", false);That works too!
Next question. The array of files are Objects. Tips on converting to string so I can load in the MidiPlayer?
The files in the array looks like:"File: E:\\Company\\Groove 06 - 155 bpm\\Pattern01.mid"I'm calling
MIDIPlayer.setFile(fileList[0], 1, 1);and getting an error:
API Call with undefined parameter 0I guess technically I just need to remove
File:from the file name
-
@ustk @d-healey Any tips on using replace() ?
I'm trying to snip the File: part off of the file name.
using:fileList = fileList.replace("File: ", "");but I'm getting the error:
Unknown function 'replace' -
replace works on strings, fileList is an array so no replace function there. You'd need to loop through your array of objects and run replace on each one.
-
@d-healey here's my attempt:
//hold file list var fileList = []; const var formattedNames = []; const var Browse = Content.getComponent("Browse"); inline function onBrowseControl(component, value) { if(value) //if button clicked { //open file broswer FileSystem.browseForDirectory("", function(dir) { //push midi list into array fileList = FileSystem.findFiles(dir, "*.mid", false); for (i = 0; i < fileList.length; i++) { var newName = fileList[i]; newName = newName.replace("File: ", ""); formattedNames.push(newName); } }); } }; Content.getComponent("Browse").setControlCallback(onBrowseControl);getting this error:
function not found at newName = newName.replace("File: ", ""); -
filelist is an array of objects. So filelist[i] is an object not a string. Try
Console.print(trace(filelist[i]));to see what is contained within your object. -
@d-healey said in Get list of midi files:
Console.print(trace(filelist[i]));
It returns
Interface: undefined -
@dustbro If you're going to copy and paste things that I write you should check that I've written it correctly ;) Your variable is called fileList, not filelist.
-
@d-healey said in Get list of midi files:
fileList

I've been sitting at the computer for 13 hours... maybe I need a break.
Now that I'm using variables that actually exist in my project, it returns empty:
Interface:Also, thanks for the help.

-
What do you get with
Console.print(fileList.length);? -
@d-healey 15, which is the amount of files in my test folder
-
Try this in place of your loop
for (f in fileList) { Console.print(f.toString(File.FullPath)); }I also notice you're using some
vars, always uselocalin inline functions, and in on init use reg or const. 99% of the timevarshould not be used except in paint routines, mouse callbacks, timer callbacks, and occasionally a few other places. -
@d-healey said in Get list of midi files:
Try this in place of your loop
Now we're talking! that returns the file path correctly
-
@dustbro Yeah it's late here :) the objects in your array are all file objects so you have access to all of the File class functions, like
toString() -
@d-healey said in Get list of midi files:
99% of the time var should not be used
Thanks for this advice as well.