PnS - Read files from folder

Official support for: bluecataudio.com
Post Reply New Topic
RELATED
PRODUCTS
Plug'n Script$99.00Buy

Post

I need to read the list of files (with given extension) from a folder provided by the user.
I've tried using the filesystem API, but it's not working form me.
When I do fs.getCurrentPath() I get the folder where the script editor is located. Weird.

Here it is a stripped example of what I'm doing:

Code: Select all

string myFolder= 'D:/music/dev/myfolder';
filesystem fs;
	
bool ok = fs.changeCurrentPath(myFolder);
if (ok) {
	print("Changed path!");
        array<string> files = fs.getFiles();
	for (uint n=0; n < files.length; n++) {
		print(files[n]);
	}	
}
I guess I'm not using the filesystem correctly, or maybe changing the folder is not allowed?

Post

That's odd. So the function returns ok=true? Have you tried with \ instead of /? Does it happen with any folder?

Post

No, the method returns false, whatever the folder I try.

I've tried forward slash and escaped backslash. No way, the filesystem folder remains unchanged, pointing to the last selection I did from the UI, either for choosing the script's editor or the script to run.

Post

Ah ok, so at least it's coherent - it fails selecting the directory.

The Angelscript fileSystem object seems to be defaulting to the app's working directory (which can be modified by many operations - do not rely on it).

Oh, after copying/pasting your code to try it out, I noticed that you used single quotes for the string, and the angelscript engine is actually configured to use single quotes for numbers (to make it closer to C++ syntax). Changing those to double quotes will fix your issue. If you print the myFolder string you will see that it has nothing to do with what you expect :-).

Post

I confirm that with double quotes it works fine. Awesome!
I'm new to Angelscript, I didn't think about such a difference, which is quite unusual for a scripting language :wink:

Post

Indeed, that's actually an option which is not activated by default in Anglescript. It was chosen to activate it to make the translation of DSP scripts from Angelscript to C++ easier for PnS.

Post Reply

Return to “Blue Cat Audio”