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

时间:2015-08-28 18:06:57

标签: javascript node.js explorer finder

我想知道是否有办法通过节点js打开文件夹位置。我找到this library但它只打开文件和网址。

编辑:Fuser的回答让我走上正轨,我发现了这个:

http://documentup.com/arturadib/shelljs

他或他的方法都可以。

2 个答案:

答案 0 :(得分:0)

使用所需的文件夹向explore发送消息。

答案 1 :(得分:0)

我还没有测试过这段代码,但这样的事情应该可以工作:

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