为什么相对路径在NWJS应用程序中不起作用?
只有绝对路径才能起作用。此代码有效。如果我使用../../../ system.user/documents/documents.nfo'
它将无法使用。
编辑:如何使用/%application%/system.user/documents/documents.nfo
之类的变量?这样可以吗?
main.js
function OpenDocuments() {
const path = require('path');
nw.Shell.showItemInFolder(path.resolve('D:/PROTON DRIVE/PROTON.USER/DOCUMENTS/DOCUMENTS.NFO'));
}
default.html
<div name="FolderMenuContainer" id="FolderMenuContainer" class="FolderMenuContainer">
<span name="FolderIcon" id="FolderIcon" class="material-icons"> description </span>
<span name="FolderText" id="FolderText" class="FolderText" onclick="OpenDocuments()"> Documents </span>
</div>
文件结构
Only absolute paths are working. This code works. If I use ../../../SYSTEM.USER/DOCUMENTS/DOCUMENTS.NFO'
it won't work.
EDIT: How can I use a variable like /%APPLICATION%/SYSTEM.USER/DOCUMENTS/DOCUMENTS.NFO
? Is that possible in this manner?
Main.js
function OpenDocuments() {
const path = require('path');
nw.Shell.showItemInFolder(path.resolve('D:/PROTON DRIVE/PROTON.USER/DOCUMENTS/DOCUMENTS.NFO'));
}
Default.html
<div name="FolderMenuContainer" id="FolderMenuContainer" class="FolderMenuContainer">
<span name="FolderIcon" id="FolderIcon" class="material-icons"> description </span>
<span name="FolderText" id="FolderText" class="FolderText" onclick="OpenDocuments()"> Documents </span>
</div>
File Structure
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用的一种方法是使用
path.join
和process.cwd()
。CWD
是指“当前工作目录”。示例:
您还可以使用
dirname
,该相对于文件执行的文件,这可能与当前的工作目录不同。如果您想使用解决方案Windows环境变量,我建议您制作这样的辅助功能:
您可能还需要解决非窗口路径
One way I use is to use
path.join
andprocess.cwd()
.cwd
means "Current Working Directory".Example:
You can also use
__dirname
which is relative to the file the code is executed from, which may be different from the Current Working Directory.If you want to use resolve Windows environment variables, I would recommend making a helper function like this:
You may also want to resolve non-windows paths
由于Jaredcheeda,能够弄清楚了!解决我问题的具体解决方案是:
每个'..'向后移动一个目录。我尝试在我的原始代码中使用../../../在我的文件路径中使用,但它不起作用。使用方法,杰罗德解释了它正在起作用!
Was able to figure it out thanks to Jaredcheeda! The specific solution to my problem is this:
Each '..' moves backwards a directory. I tried using the ../../../ in my file path in my original code and it wasn't working. Using the method Jerod explained it is working!