gpt4 book ai didi

file - 如何使用 Electron 对话框选择文件夹或文件?

转载 作者:行者123 更新时间:2023-12-03 12:30:58 66 4
gpt4 key购买 nike

我希望能够选择整个目录或多个或单个文件。

我只能选择一种类型,因此只能根据创建对话框时使用的选项来选择文件或目录。我知道我可以创建两个单独的选项来选择文件夹或文件,但是将其放在一个对话框中会更方便。

//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'],将显示目录选择器。”

我将保留它,以防有人可以使用此信息

关于file - 如何使用 Electron 对话框选择文件夹或文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57867302/

66 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com