问题描述
在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?
推荐答案
此处讨论了此问题的答案: https://groups.google.com/d/topic/node-webkit/IwGzluFC9iU/discussion
The answer to this question was discussed here: https://groups.google.com/d/topic/node-webkit/IwGzluFC9iU/discussion
这对我有用,无论它与压缩的"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中获取当前应用程序的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!