Copy link to clipboard
Copied
var file = File.openDialog();
alert("file:" + file);
Below is the result after I choose to select "my.json":
If I don't want to do it manually, it it directly opens this path “pathToMyJSONFile” (pathToMyJSONFile = File($.fileName).parent.parent + ‘/PubLib/my.json’;)
How do I change it?
var file = File.open(pathToMyJSONFile);
This seems wrong.
alert(pathToMyJSONFile); results in this:
Something like this would read the contents of a text file:
var p = File(Folder.desktop + "/test.json");
var t = readFile(p)
alert(t);
/**
* Read a text file
* @ param the file path of the file
* @ return the text in the file
*/
function readFile(p) {
var f = new File(p);
f.open("r");
var x = f.read();
f.close();
return x;
}
Copy link to clipboard
Copied
Tried it out. I tried multiple ......
Looks like this:
file = File(pathToMyJSONFile);
Copy link to clipboard
Copied
Something like this would read the contents of a text file:
var p = File(Folder.desktop + "/test.json");
var t = readFile(p)
alert(t);
/**
* Read a text file
* @ param the file path of the file
* @ return the text in the file
*/
function readFile(p) {
var f = new File(p);
f.open("r");
var x = f.read();
f.close();
return x;
}
Copy link to clipboard
Copied
Hi rob day.
I tried out this one.
Thank you very much.
Copy link to clipboard
Copied
File.open() will not open a json or text file—open() is expecting an InDesign file path— .indt, .indd, idml
Find more inspiration, events, and resources on the new Adobe Community
Explore Now