electron 打开本地文件夹

使用的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`)
相关推荐
NeilCarmack1 天前
Deepseek-harness增加桌面版端序列:第 2 讲 · spawn Electron:当前进程如何“交棒“
前端·javascript·electron
绿岛之北1 天前
Electron 安全第三章:URL 加载与 WebView
前端·electron
菜鸟前端程序员2 天前
当 AI 文件遇上 PDF:一个基于 Electron + Ghostscript 的矢量格式转换引擎深度剖析
electron
clorinda3 天前
把 DeepSeek Harness 打包成类似 Codex 的 Windows 桌面应用:Electron、一键启动、插件管理和动态壁纸
前端·javascript·windows·electron
晴天165 天前
Mojo IPC 和 Electron 的关系-Day21
javascript·electron·mojo
卸任5 天前
AI英语学习助手:从翻译工具到 AI 英语学习助手
前端·electron
kaixin_learn_qt_ing5 天前
Electron程序---初体验
javascript·electron
晴天166 天前
Electron面试题-Day19
java·javascript·electron
绿岛之北6 天前
Electron 安全入门:为什么一个 XSS 可能变成 RCE?
前端·electron
明快de玄米617 天前
Electron学习文档
学习·electron·vim