如何使用电子获得文件夹path

我对电子很陌生。 任何人都可以build议我如何获得本地文件夹的相对path使用电子。 JavaScript没有这种能力。

在这里输入图像描述

我有一个select文件button(见快照),所以当我select一个文件夹,然后单击打开button,那么它应该返回一个完整的目录path。

正如@phuongle在你要使用showOpenDialog()的注释中指出的那样。 像这样的东西:

 var remote = require('remote'); var dialog = remote.require('electron').dialog; var path = dialog.showOpenDialog({ properties: ['openDirectory'] }); 

更新:上述不适用于当前版本,您必须使用ES6导入..

 const {dialog} = require('electron').remote; 

在Electron中,我们可以通过指定type =“file”和webkitdirectory属性“的简单input元素来select目录。 我们可以通过File对象的path属性document.getElementById("myFile").files[0].path获取目录的完整pathdocument.getElementById("myFile").files[0].path

你会使用Node的path.relative