本文介绍了Electron 在特定应用程序中打开文件/目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Electron 构建一种文件浏览器/查找器.我想用特定的应用程序打开一些文件类型.

I'm building a sort of File explorer / Finder using Electron.I want to open some file types with a specific application.

我已经尝试过这个答案的方法:用 Electron 打开外部文件

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'])

但是当我这样做时,我得到一个 EACCES 错误,如下所示.

But when I do that, I get a EACCES error as follows.

这是正确的方法吗?如果是,我该如何解决这个问题?如果没有,正确的方法是什么?

推荐答案

您可以通过电子模块的shell命令打开文件或文件夹.这些命令适用于主进程和渲染器进程.

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.

有关 https://github.com/electron 的更多信息/electron/blob/master/docs/api/shell.md

这篇关于Electron 在特定应用程序中打开文件/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 20:12
查看更多