How do you show a file in windows explorer using Go?
This command works as expected from the command line:
explorer /select,C:\data\My File.txt
I can't get the same command to work using Go's exec.Command()
method, no matter what combination of arguments tried.
This works:
exec.Command(`explorer`, `/select,C:\data\MyFile.txt`) // SUCCEEDS
but fails with a space in the filename.
exec.Command(`explorer`, `/select,C:\data\My File.txt`) // FAILS
Notes:
You can get it to work if you separate the /select,
action and the actual path, and you pass them as separate parameters:
exec.Command(`explorer`, `/select,`, `C:\data\My File.txt`)
A more complete answer for the golang newbies (like myself):
package main
import (
"os/exec"
)
func main() {
cmd := exec.Command(`explorer`, `/select,`, `C:\data\My File.txt`)
cmd.Run()
}