FileSystem.findFiles(var directory, String wildcard, bool recursive)
-
So I'm using this call...or trying to....
sadly it takes a few seconds to return the array of file names....so really it would be better to have this
FileSystem.findFiles(var directory, String wildcard, bool recursive, function(){
})
but meanwhile... how is every one dealing with the waiting game - a timer?
-
No, actually that's a good request, since the scripting engine is not supposed to wait for multiple seconds (which is why all of those things require an asynchronous function call).
I just wasn't aware that this operation might take more time, because I only tested it with small amounts of files, but I can imagine that it will take a bit if you have thousands of files (or if you have a slow USB drive or whatever)
-
@christoph-hart said in FileSystem.findFiles(var directory, String wildcard, bool recursive):
No, actually that's a good request, since the scripting engine is not supposed to wait for multiple seconds (which is why all of those things require an asynchronous function call).
I just wasn't aware that this operation might take more time, because I only tested it with small amounts of files, but I can imagine that it will take a bit if you have thousands of files (or if you have a slow USB drive or whatever)
Yeah - Im testing on a "slow USB drive" to make sure I catch this sort of thing...
-
My vote is for the callback, breaking change is okay with me :)
- about a year later
-
@d-healey @Lindon
Hello, is it possible to iterate in an array that contains the files using the findFiles function?var filesArray = FileSystem.findFiles(mydirectory, "*.format", false); Console.print(filesArray); //prints "[Array]"
The moment I try to iterate over the array to see if the files are correct, it gives me error or prints nothing.
for (i in filesArray) { Console.print(filesArray[i]); }//API Call with undefined parameter
Any ideas? Thanks
-
@Sawer You're misunderstanding how the
for in
loop works. -
@d-healey Uhh, right! I figurdìed it now. Thanks for the catch!
for (i in filesArray) { Console.print(i); } //Nothing comes out now
What about this?
-
@Sawer
i
is a file object, so what do you expect the output to be? Also probably better to usef
instead ofi
, or even the wordfile
to be really clear about what the object is. -
@d-healey An object and its id, maybe? something like "Object 0x3b35018" ?
for (file in filesArray) { Console.print(file); }
Here you go :)
Probably it's a kind of different object, I get it.
Is there a way to stringify it and get the name of the file? -
@Sawer Type File in the API browser to see all of the functions that are available for File objects.
https://docs.hise.audio/scripting/scripting-api/file/index.html#tostring
-
@d-healey Thanks.
Do spaces in a path make the function not to work? because it's still now working. I'm wondering if it is that -
@Sawer Spaces in the paths are fine. Are you sure your array has been populated (use the script watch table to check)?
-
@d-healey True, I checked now and after I Compiled, the array is not yet populated.
-
@Sawer
Do all files work or only text files? Because I just want to get the name of each sample file in the project sample folder, using the FileSystem API. -
@Sawer All files, but the samples won't be in the project folder on the user's system.
Do your samples have a
.format
extension?Perhaps use this function
-
@d-healey the format was just an example name: the wildcard is "*.wav"
Will try that function now and give you a feedback. Thanks -
@d-healey For instance, I'm now trying the same thing with an XML, and still the array is not populated. Strange..
-
@Sawer Need to see more of your code to know what you're doing wrong.
-
@d-healey True.
inline function fetchSamplesDirectory(component, value) { if (value == 1) FileSystem.browseForDirectory(FileSystem.Desktop, function(folder) { if(isDefined(folder) && folder.isDirectory()) { var samplesPath = folder.toString(folder.FullPath); //samples directory variable var samplesArray = FileSystem.findFiles(samplesPath, "*.wav", false); //Array of samples Console.print(samplesArray); } }); };
I have not been iterating over the array cause it's still not populated.
-
@Sawer You don't need to pass a string to the findFiles function. Just pass in the
folder
variable.