使用的api为
shell.openPath
,有些文章会提到shell.openItem
,这个方法在electron 9.0
后就废弃被openPath
替代了。
- 打开E盘根目录下名为
test
的文件夹
javascript
const { shell } = require('electron')
shell.openPath('E:\\test')
能打开的前提是,E盘根目录下确实有这个文件夹。其次可以发现,我路径上使用的是
\\
而非/
,如果使用/
的话,openPath
方法会直接报错。
- 打开
当前electron项目
根目录下名为src
的文件夹
javascript
const { app , shell } = require('electron')
shell.openPath(`${app.getAppPath()}\\src`)