[英]Electron: Log path of file selected from showOpenDialog box
I am making an electron app and I need to get the path of a file selected in the electron open dialog box.我正在制作一个 electron 应用程序,我需要获取在 electron 打开对话框中选择的文件的路径。 I intend to get the path in the main process and then send it to the renderer.我打算在主进程中获取路径,然后将其发送给渲染器。
This is my current code:这是我当前的代码:
dialog.showOpenDialog(options, (filePaths) => {
console.log(filePaths)
}
However when I select a file nothing is logged to the console?但是,当我 select 文件没有记录到控制台时? How can I log the path to the console?如何记录控制台的路径?
The latest documentation shows that showOpenDialog returns a Promise.最新文档显示 showOpenDialog 返回 Promise。
To access the file path, check after it has been resolved as so:要访问文件路径,请在解析后检查:
let path = dialog.showOpenDialog({
properties: ['openDirectory']
}).then((obj) => {
console.log(obj.filePaths);
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.