admin管理员组文章数量:1302902
I am trying to see if a file exists locally like this:
if (exec(`-f ~/.config/myApp/bookmarks.json`)) {
console.log('exists')
} else {
console.log('does not')
}
However, I get exists in the console whether the file exists or not
I am trying to see if a file exists locally like this:
if (exec(`-f ~/.config/myApp/bookmarks.json`)) {
console.log('exists')
} else {
console.log('does not')
}
However, I get exists in the console whether the file exists or not
Share asked Dec 18, 2018 at 21:14 ss_matchesss_matches 5172 gold badges6 silver badges21 bronze badges1 Answer
Reset to default 9You should import the fs
module into your code.
If you're running on the main
process, then do a simple const fs = require('fs');
but if you're on the renderer process then run const fs = require('electron').remote.require('fs')
Then with the fs
module you can run a simple exists method on the file:
if (fs.existsSync(`~/.config/myApp/bookmarks.json`)) {
console.log('exists')
} else {
console.log('does not')
}
Although you really should check for this asynchronously:
fs.access(`~/.config/myApp/bookmarks.json`, (err) => {
if (err) {
console.log('does not exist')
} else {
console.log('exists')
}
})
本文标签: javascriptHow do you check if a file exist locally with an electron appStack Overflow
版权声明:本文标题:javascript - How do you check if a file exist locally with an electron app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741677026a2391940.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论