学习 Electron 我想在 drag and drop 之后进行一些文件处理。在 Mac 上,tmp 的等效项是 $TMPDIR
。引用 app
的 API 文档,我能够找到 app.getAppPath()
,它显示了来自 main.js 的简单控制台日志的路径。在 app.getAppPath()
下面有 getPath()
,但是当我尝试 app.getPath(temp)
时:
let foobar = app.getAppPath("temp")
console.log(foobar)
我在控制台中收到错误:
ReferenceError: temp is not defined
通过我的研究,我读到:
- How to store user data in Electron
- How to get the original path of a portable Electron app?
- Creating and Using Temporary Files
- Get Special folder Path in Electron
- electron temp directory
- How to set a custom path for Electron app installer
在 Electron 中,是否有一个内置的临时目录可以在所有操作系统上工作,或者有一个可以引用的进程
?
注意:
即使在引用以下字符串之后:
console.log(`The temp path is: ${app.getAppPath("temp")}`)
它返回与以下内容相同的响应:
console.log(`The AppPath is: ${app.getAppPath()}`)
这是:
The temp path is: /Users/Grim/Documents/GitHub/electron-quick-start-boilerplate
The AppPath is: /Users/Grim/Documents/GitHub/electron-quick-start-boilerplate
以及上面的console.log
测试已添加在letWindow
之后。
最佳答案
app.getAppPath()
不接受参数。
对于app.getPath(name)
,参数应该是字符串 "temp"
:app.getPath("温度”)
。
关于node.js - 在 Electron 应用程序中如何引用临时路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55005208/