Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Node.js FileSystem access返回enoint,尽管文件存在_Javascript_Node.js_Electron - Fatal编程技术网

Javascript Node.js FileSystem access返回enoint,尽管文件存在

Javascript Node.js FileSystem access返回enoint,尽管文件存在,javascript,node.js,electron,Javascript,Node.js,Electron,我有一个node.js函数,它使用fs.access检查文件是否存在,是否可读写: function StackOverFlowFunction() { try { fs.accessSync(`file://${__dirname}/config/config.ini`, fs.constants.F_OK | fs.constants.R_OK | fs.constants.W_OK); } catch (err) { console.log(err); } 尽管文件已经存

我有一个node.js函数,它使用fs.access检查文件是否存在,是否可读写:

function StackOverFlowFunction() {
try {
    fs.accessSync(`file://${__dirname}/config/config.ini`, fs.constants.F_OK | fs.constants.R_OK | fs.constants.W_OK);
} catch (err) {
    console.log(err);
}
尽管文件已经存在

{ Error: ENOENT: no such file or directory, access 'file:///home/callcenter1/BookGenerator/config/config.ini'
at Error (native)
at Object.fs.accessSync (fs.js:248:11)
at Object.fs.accessSync (ELECTRON_ASAR.js:420:27)
at getConfig (/home/callcenter1/BookGenerator/main.js:12:12)
at Object.<anonymous> (/home/callcenter1/BookGenerator/main.js:18:10)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
errno: -2,
  code: 'ENOENT',
  syscall: 'access',
  path: 'file:///home/callcenter1/BookGenerator/config/config.ini' }
{错误:enoint:没有这样的文件或目录,access'file:///home/callcenter1/BookGenerator/config/config.ini'
错误(本机)
在Object.fs.accessSync(fs.js:248:11)
在Object.fs.accessSync(ELECTRON_ASAR.js:420:27)
在getConfig(/home/callcenter1/BookGenerator/main.js:12:12)

在对象上。

使用正确的文件系统路径,而不使用方案:

fs.accessSync(`${__dirname}/config/config.ini`, ...)

使用正确的文件系统路径,而不使用方案:

fs.accessSync(`${__dirname}/config/config.ini`, ...)

你检查过同一文件夹中的其他文件吗?我想你有错误的路径。我看起来很奇怪
文件://${{uu dirname}/config/config.ini
。你不能这样使用它:
${{uu dirname}/config/config.ini
你检查过同一文件夹中的其他文件吗?我想你有错误的路径。我看起来很奇怪
文件://${uu dirname}/config/config.ini
。你就不能这样使用它:
${{uu dirname}/config/config.ini
Electron的
win.loadURL('file://${uu dirname}/app/app.html');
工作得很好。尽管如此,还是尝试了,错误仍然存在。
win.loadURL()
加载URL;
fs
用于文件系统操作。答案尚未完成,因为只有在删除
$(\uuu dirname)
时,解决方案才能解决问题。@Propolys我拒绝了该编辑,因为它与问题的答案不匹配。问题中生成的路径(以及给出错误的路径)基本正确,但仍使用
\uuuu dirname
。您确定使用的是括号(
${uuu dirname}
)而不是括号(
$(\uu dirname)
)。@Propolys
\uuu dirname
包含调用它的
.js
文件的目录的绝对路径:)Electron的
win.loadURL('file://${uu dirname}/app/app.html');
工作正常。尽管尝试了此操作,但错误仍然存在。
win.loadURL()
加载URL;
fs
用于文件系统操作。答案尚未完成,因为只有在
$(\uu dirname)的情况下,解决方案才能真正解决问题
已被删除。@Propolys我拒绝了该编辑,因为它与问题的答案不匹配。在您的问题中生成的路径(以及给出错误的路径)基本上是正确的,但仍然使用
\uuuu dirname
。您确定使用括号(
${\uu dirname}
)而不是括号(
$(\uu dirname)
).@Propolys
\uuu dirname
包含调用它的
.js
文件目录的绝对路径:)