【发布时间】:2019-09-10 08:57:19
【问题描述】:
我希望能够选择整个目录或多个或单个文件。
我只能选择一种类型的文件或目录,具体取决于我在创建对话框时使用的选项。我知道我可以创建两个单独的选项来选择文件夹或文件,但将它放在一个对话框中会更方便。
//opens dialog window
var selectStl = () => {
dialog.showOpenDialog({
title: "Choose STL Models",
buttonLabel: "Choose Files",
defaultPath: app.getPath("desktop"),
properties: ["multiSelections", "openFile", "openDirectory"],
filters: [
{name: 'stl', extensions: ['stl']}
]
}, filepath => {
filepath.forEach(filePath => {
if(filePath.includes(".stl") || filePath.includes(".STL")){
stlList.innerHTML += `<option>${filePath}</option>`;
}else{
fs.readdir(filePath, (err, files) =>{
files.forEach(file => {
if(file.includes(".stl") || file.includes(".STL")){
var path = filePath + "\\" + file;
stlList.innerHTML += "<option>" + path + "</option>";
}
})
})
}
})
})
}
预期:应该能够选择文件夹,或者如果我打开文件夹中的文件。
实际:我可以选择目录,但如果我进入它,文件不会出现。似乎“openDirectory”属性获得了更高的优先级。
【问题讨论】:
-
我刚刚在文档上阅读了这个“注意:在 Windows 和 Linux 上,打开的对话框不能同时是文件选择器和目录选择器,所以如果您将属性设置为 ['openFile', 'openDirectory '] 在这些平台上,将显示一个目录选择器。”我将保留它以防有人可以使用此信息
-
如果您将评论移至答案并接受它,那肯定会更引人注目。
-
会做,会做,还要等2天
标签: file directory dialog electron