Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Electron, how to allow users to pick a file path

I have an Electron App in which when users click on a button I want to open file explorer (or Finder on Mac) for users to choose a path in their file system. Then I want to use this path to save a file.

The second part is quiet easy to achieve. I just need to use writeFile() from node File System API.

However I have gone through the full list of node File System API and I have found nothing allowing me to do the first part.

like image 727
Todanley Avatar asked Apr 17 '18 23:04

Todanley


1 Answers

You should use dialogue module. Simple example for showing the file explorer will be:

  const {dialog} = require('electron')
  console.log(dialog.showOpenDialog({properties: ['openFile', 'openDirectory', 'multiSelections']}))

Check this link for more information.

like image 144
Zoran Pandovski Avatar answered Oct 11 '22 21:10

Zoran Pandovski