Hilbish/util/util_windows.go

40 lines
695 B
Go
Raw Normal View History

2024-07-19 13:48:01 +00:00
//go:build windows
package util
import (
"path/filepath"
"os"
2024-12-29 05:48:11 +00:00
"hilbish/util"
)
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 {
2024-12-29 05:48:11 +00:00
if util.Contains(pathExts, nameExt) { return nil }
return util.ErrNotExec
}
}
} else {
_, err := os.Stat(path)
if err == nil {
2024-12-29 05:48:11 +00:00
if util.Contains(pathExts, nameExt) { return nil }
return util.ErrNotExec
}
}
return os.ErrNotExist
}