Skip to main content
Participating Frequently
January 14, 2023
解決済み

fs.readdir permission denied to read directory, but I can read files from directory

  • January 14, 2023
  • 返信数 1.
  • 1360 ビュー
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");

 

 

返信数 1

Inspiring
January 14, 2023

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");

 

 

Participating Frequently
January 14, 2023

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?

Inspiring
January 15, 2023

I don't know if local path can be used.

You can get home directory path.

require("fs").readdirSync(`file:${require("os").homedir()}/Desktop`);