nwjs怎么获取app所在的目录

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

阅读 7.8k
2 个回答

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

// process.execPath 获取 exe 文件的路径
// 获取当前exe文件所在的目录路径
// 注意更改 slice 的第二个参数,因为我的 exe 文件名为 租船管理系统.exe,所以为 -10
var execDirPath = process.execPath.slice(0, -10);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进