How to select a directory with native desktop API in electron APP

dialog.showOpenDialog can help.

Code example

const { dialog } = require('electron')

const selectDirectory = async () => {
    const result = await dialog.showOpenDialog(null, {
        properties: ['openDirectory']
    })
    if (result.canceled) {
        return null
    } else {
        const dir = result.filePaths[0]
        return dir
    }
}
Posted on 2023-05-04