[英]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.