I'm building a sort of File explorer / Finder using Electron. I want to open some file types with a specific application.
I've tried the approach from this answer: Open external file with Electron
import { spawn } from 'child_process' spawn('/path/to/app/superApp.app', ['/path/to/file'])
But when I do that, I get a EACCES
error as follows.
Is this the right approach? If yes, how can I fix the issue? If not, what is the right approach?
You can open a file or folder through shell commands from the electron module. The commands work on both main and renderer process.
const {shell} = require('electron') // deconstructing assignment shell.showItemInFolder('filepath') // Show the given file in a file manager. If possible, select the file. shell.openPath('folderpath') // Open the given file in the desktop's default manner.
More info on https://github.com/electron/electron/blob/master/docs/api/shell.md
For display native system dialogs for opening and saving files, alerting, etc. you can use dialog module from electron package.
const electron = require('electron'); var filePath = __dirname; console.log(electron.dialog.showOpenDialog)({ properties:['openFile'], filters:[ {name:'Log', extentions:['csv', 'log']} ] });
A very prompt explanation is provided at Electron Docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With