Hilbish/util/util_windows.go

38 lines
658 B
Go
Raw Normal View History

2024-07-19 13:48:01 +00:00
//go:build windows
package util
import (
"path/filepath"
"os"
)
func FindExecutable(path string, inPath, dirs bool) error {
nameExt := filepath.Ext(path)
pathExts := filepath.SplitList(os.Getenv("PATHEXT"))
if inPath {
if nameExt == "" {
for _, ext := range pathExts {
_, err := os.Stat(path + ext)
if err == nil {
return nil
}
}
} else {
_, err := os.Stat(path)
if err == nil {
if Contains(pathExts, nameExt) { return nil }
return ErrNotExec
}
}
} else {
_, err := os.Stat(path)
if err == nil {
if Contains(pathExts, nameExt) { return nil }
return ErrNotExec
}
}
return os.ErrNotExist
}