Electron-dailog选择文件
进程:主进程
const { dialog } = require('electron')
dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'] })
进程:渲染进程
const { dialog } = require('electron').remote
dialog.showOpenDialog({ properties: ['openFile', 'multiSelections'] })
结果:取消
{ canceled: true filePaths: Array(0) }
结果:成功
{ canceled: false filePaths: ["E:\dirname\fileName1.md","E:\dirname2\fileName2.md"]
}
dialog.showOpenDialog([browserWindow, ]options)
browserWindowBrowserWindow (可选)选项对象titleString (可选) - 对话框窗口的标题defaultPathString (可选) - 对话框的默认展示路径buttonLabelString (可选) - 「确认」按钮的自定义标签, 当为空时, 将使用默认标签。filtersFileFilter[] (可选)propertiesString-包括对话框应当使用的特性。 支持以下属性值:openFile- 允许选择文件openDirectory- 允许选择文件夹multiSelections-允许多选。showHiddenFiles-显示对话框中的隐藏文件。createDirectorymacOS -允许你通过对话框的形式创建新的目录。promptToCreateWindows-如果输入的文件路径在对话框中不存在, 则提示创建。 这并不是真的在路径上创建一个文件,而是允许返回一些不存在的地址交由应用程序去创建。noResolveAliasesmacOS-禁用自动的别名路径(符号链接) 解析。 所选别名现在将会返回别名路径而非其目标路径。treatPackageAsDirectorymacOS -将包 (如.app文件夹) 视为目录而不是文件。dontAddToRecentWindows - Do not add the item being opened to the recent documents list.
messageString (可选) macOS -显示在输入框上方的消息。securityScopedBookmarksBoolean (optional) macOS mas - Create security scoped bookmarks when packaged for the Mac App Store.
Returns Promise<Object> - Resolve with an object containing the following:
canceledBoolean - whether or not the dialog was canceled.filePathsString[] - 用户选择的文件路径的数组. If the dialog is cancelled this will be an empty array.bookmarksString[] (optional) macOS mas - An array matching thefilePathsarray of base64 encoded strings which contains security scoped bookmark data.securityScopedBookmarks必须启用才能捕获数据。 (For return values, see table here.)
browserWindow 参数允许该对话框将自身附加到父窗口, 作为父窗口的模态框。

浙公网安备 33010602011771号