How to get folder path using electron
As @phuongle pointed out in the comments you want to use showOpenDialog()
. Something like this:
var remote = require('remote');
var dialog = remote.require('electron').dialog;
var path = dialog.showOpenDialog({
properties: ['openDirectory']
});
UPDATE: If the above isn't working for your current Electron version, you should try more modern importing:
const {dialog} = require('electron').remote;
In addition, in order to use remote
, you need to set enableRemoteModule
when creating your window in your main process:
const myWindow = new BrowserWindow({
webPreferences: {
enableRemoteModule: true
}
});
In Electron we can select the directory by specifying simple input element with type="file" and webkitdirectory attribute'.
<input id="myFile" type="file" webkitdirectory />
and we can get the directory full path with the path property of File object document.getElementById("myFile").files[0].path