我想知道是否有一种方法可以通过node js打开文件夹位置。我找到了这个库,但它只打开文件和url。
编辑:Fuser的回答让我走上了正确的轨道,我发现了这个: http://documentup.com/arturadib/shelljs要么他的方法,要么这个都可以。
只需使用fs.exec
或fs.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('fs.execSync', `${command} "${dirPath}"`);
return fs.execSync(`${command} "${dirPath}"`);
}
直接在explorer
中添加所需的文件夹。