[英]Opening Explorer to a specific file in Node.js
我已经查看了一些相关的问题,并且存在将explorer.exe
打开到特定文件的方法,以便在Explorer窗口中选择它。 命令行是这样的:
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"]);
}
})
}
它有效,但是。
这样做的正确方法是什么?
您是否尝试将explorer.exe作为可执行文件而不是cmd.exe运行?
const expl = exec('explorer.exe', [`/select,"${root}\\${filename}\"`]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.