使用explorer.exe或finder使用node js打开文件夹窗口

8ljdwjyq  于 11个月前  发布在  Node.js
关注(0)|答案(2)|浏览(180)

我想知道是否有一种方法可以通过node js打开文件夹位置。我找到了this library,但它只能打开文件和URL。
编辑:Fuser的回答让我走上了正确的道路,我发现了这个:
http://documentup.com/arturadib/shelljs
他的方法和这个都行。

bnl4lu3b

bnl4lu3b1#

只需使用child_process.execchild_process.execSync沿着正确的shell命令即可。下面是一个工作示例:

function dirOpen(dirPath) {
  let command = '';
  switch (process.platform) {
    case 'darwin':
      command = 'open';
      break;
    case 'win32':
      command = 'explorer';
      break;
    default:
      command = 'xdg-open';
      break;
  }
  console.log('child_process.execSync', `${command} "${dirPath}"`);
  return child_process.execSync(`${command} "${dirPath}"`);
}

字符串

vof42yt1

vof42yt12#

只需将所需的文件夹发送到explorer

相关问题