【发布时间】:2016-07-19 11:26:08
【问题描述】:
我查看了一些相关问题,并且存在将explorer.exe 打开到特定文件的方法,以便在资源管理器窗口中选择它。命令行是这样的:
explorer.exe /select,"C:\Temp\Myfile.png"
我直接在命令提示符下运行该命令以验证它是否有效,并且确实有效。但是,我无法让它以一种好的方式在 Node 中运行。我尝试过的一些事情:
const expl = exec('cmd.exe', ["explorer.exe", `/select,"${root}\\${filename}\"`]);
const expl = spawn('cmd.exe', ["explorer.exe", `/select,"${root}\\${filename}\"`]);
const expl = exec('cmd.exe', [`explorer.exe /select,"${root}\\${filename}\"`]);
...以及其他一些变体。我不/不知道自己在做什么。
我最终写出了一个真正丑的解决方案:
function openExplorerSelected(filename){
let batfile = `explorer.exe /select,\"${root}\\${filename}\"`;
fs.writeFile("tmp.bat", batfile, function(err){
if( err ) console.warn(err);
else {
const expl = spawn('cmd.exe', ["/c", "tmp.bat"]);
}
})
}
它有效,但是。
这样做的正确方法是什么?
【问题讨论】:
标签: javascript node.js fs