Lesson 6 of 28 · javascript
Native Dialogs – Open & Save Files
Duration: 9 mins
Native Dialogs – Open & Save Files
Electron's dialog module opens OS‑native file/folder pickers.
const { dialog } = require('electron');
// Open a file picker (allow multiple)
async function pickFiles(){
const { canceled, filePaths } = await dialog.showOpenDialog({
title: 'Select a file',
properties: ['openFile', 'multiSelections']
});
if (!canceled) return filePaths; // array of selected paths
}
// Save dialog
async function pickSave(){
const { canceled, filePath } = await dialog.showSaveDialog({
title: 'Save as',
defaultPath: 'untitled.txt'
});
if (!canceled) return filePath;
}
You can call these functions from the main process or via the preload bridge.