Surjeet Bhadauriya Surjeet Bhadauriya - 3 years ago 145
Node.js Question

How to get folder path using electron

I am very new with electron. Can anyone suggest me how to get a local folder's relative path using the electron. JavaScript does not have that capability.

enter image description here

I have a Choose File button(see snapshot), so when i select a folder and click on open button then it should return a whole directory path.

Answer Source

As phuongle pointed out 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: the above isn't working for the current version, and you must import the dialog as follows..

const {dialog} = require('electron').remote;

var path = dialog.showOpenDialog({
    properties: ['openDirectory']
});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download