Can't set where my JSON file gets written to.
Hi Max community,
I want to specify the directory where my json gets saved to, but it keeps saving the file in the application directory. I want it to save it in a folder below where the patch is saved. Below is the code I'm currently using. Can anyone help
f = new File("DrumClipData.json", "write", "TEXT");
if (f.isopen) {
post("writing string to file: " + f.filename + "in: " + f.foldername + "\n");
f.writestring(JSON.stringify({data: retClips})); //writes a string
f.close();
}
else {
post("could not create file: " + f.filename + "in: " + f.foldername + "\n");
}
Also, I'd like to add I've tried putting a path before the filename and that doesn't seem to work.
Figured it out. Needed to pass the path correctly using the outlet of the thispatcher object.
Just in case someone else is looking for something a bit more basic, you can just reference the full path as a variable.
var memstr;
var mem = new Object();
var UI = new Object();
var p = "/Users/username/Folder Number 1/writeToJson.json";
function write(){
read();
anything(trackNumber, currentClip, arrayOfParamValues.join(' '));
var jase = JSON.stringify(UI,null,'\t');
var path = p;
var fout = new File(path,"write","TEXT");
if (fout.isopen) {
fout.writeline(jase);
fout.close();
post("\nJSON Write",path);
} else {
post("\ncould not create json file: " + path);
}
}