在node-webkit中获取当前应用程序的路径 [英] Get the path to the current application in node-webkit

查看:127
本文介绍了在node-webkit中获取当前应用程序的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在node-webkit中,有什么方法可以找到当前应用程序的路径?在node.js中,可以使用__dirname查找当前应用程序的路径,但是在node-webkit中,变量__dirname似乎未定义.

In node-webkit, is there any way to find the path to the current application? In node.js, you can use __dirname to find the path to the current application, but in node-webkit, the variable __dirname appears to be undefined.

以下node.js脚本可正确打印文件路径:

The following node.js script prints the file path correctly:

console.log(__dirname)

以下node-webkit脚本无法正确打印文件路径:

The following node-webkit script does not print the file path correctly:

<script type = "text/javascript">
    alert(__dirname);
</script>

在node-webkit中找到当前应用程序路径的正确方法是什么?

What is the correct way to find the path to the current application in node-webkit?

推荐答案

此处讨论了此问题的答案:

The answer to this question was discussed here: https://groups.google.com/d/topic/node-webkit/IwGzluFC9iU/discussion

在Windows上,使用"process.execPath"查看启动它的可执行文件的路径.然后从那里开始工作,从路径中删除可执行文件的文件名,以获取文件夹的路径(假设您应用的.nw是相对于可执行文件或与可执行文件结合的.)

On Windows, use "process.execPath" to see the path of the executable that launched it. Then work from there, removing the executable's filename from the path to get the folder's path (assuming your app's .nw is relative to the executable or is combined with it).

这对我有用,无论它与压缩的"app.nw"一起运行还是将"nw.exe"和"app.nw"组合到一个可执行文件(app.exe)中.

This works for me whether it is running with the zipped 'app.nw' or where 'nw.exe' and 'app.nw' are combined into one executable file (app.exe).

这篇关于在node-webkit中获取当前应用程序的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆