nwjs怎么获取app所在的目录

发布于 2022-09-01 12:54:54 字数 77 浏览 8 评论 0

打包后的nwjs应用在运行时,会随机将app目录解压到c盘user appdata的temp目录中,怎么在运行时获取这个随机的目录位置?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

恏ㄋ傷疤忘ㄋ疼 2022-09-08 12:54:54

I want to build some data on the current directory ? But how to get the current directory?
console.log(__dirname)
I try that, but it doesn't work.
I want a little help.
Some temp files were built in the temp directory when it work on. How to get the real dirname?

answer:

Just so you know your project is compressed, packed, and concatenated into the binary. So when it runs it will unpack to a temp directory in order to be accessed.

Get path of project directory (temp dir):

console.log(process.cwd());
Get path of project binary:

var path = require("path");
console.log(path.dirname(process.execPath));

酒解孤独 2022-09-08 12:54:54
// process.execPath 获取 exe 文件的路径
// 获取当前exe文件所在的目录路径
// 注意更改 slice 的第二个参数,因为我的 exe 文件名为 租船管理系统.exe,所以为 -10
var execDirPath = process.execPath.slice(0, -10);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文