Copy link to clipboard
Copied
const fs = require("fs");
const paths = fs.readdirSync("test");
console.log(paths);
above gives the error: "Permission denied to read directory. Engine: UXPScript File: I (uxp://uxp-internal/webfs-scripts.js)"
The below works fine:
const fs = require("fs");
let txt = fs.readFileSync("test\\test.txt", {encoding: "utf-8"});
console.log(txt);
lstatSync gives [console] {"_info":{"isFile":false,"isDirectory":true}}
Giving it all possible permissions, and opening InDesign as admin didn't help.
I'm on Windows 10 Pro
Is there any other way to grep the content of the directory?
You may need to specify a "file:" scheme.
In my case the following UXP Script worked.
const myFs = require("fs");
const myFilesAndDirectoriesList = myFs.readdirSync("file:C:/Users/user/Desktop");
Copy link to clipboard
Copied
You may need to specify a "file:" scheme.
In my case the following UXP Script worked.
const myFs = require("fs");
const myFilesAndDirectoriesList = myFs.readdirSync("file:C:/Users/user/Desktop");
Copy link to clipboard
Copied
Thank you very much! It works if I provide a full path.
However, it reads files from the local path, but returns a blank error message and "-4058" in the console if I try local path to the folder like this:
"file:test"
"file:\\test"
"file:test\\"
"file:\\test\\"
What is "4085"? Is there any way around it?
Copy link to clipboard
Copied
I don't know if local path can be used.
You can get home directory path.
require("fs").readdirSync(`file:${require("os").homedir()}/Desktop`);
Copy link to clipboard
Copied
Thank you very much! It solves it. Also, I discovered another method that gives me the whole path:
app.activeScript
On Widows:
C:\Users\<User>\AppData\Roaming\Adobe\InDesign\Version 18.0\en_US\Scripts\Scripts Panel\test.idjs
I just have to replace to remove the text after the last slash and add the folder name.
let scriptPath = app.activeScript;
if (/\//.test(scriptPath)) {
scriptPath = scriptPath.replace(/(.*\/).*$/, "$1");
}else{
scriptPath = scriptPath.replace(/(.*\\).*$/, "$1");
}const paths2 = fs.readdirSync(`file:${scriptPath}test`);
Hope it will be useful for others too.