Fix: get execute file path dynamically

This commit is contained in:
HFO4
2020-03-11 10:32:35 +08:00
parent b6e1e04ce0
commit 4d70f9fa3e
12 changed files with 27 additions and 16 deletions

View File

@ -1,7 +1,9 @@
package util
import (
"os"
"path"
"path/filepath"
"strings"
)
@ -45,3 +47,12 @@ func SplitPath(path string) []string {
func FormSlash(old string) string {
return path.Clean(strings.ReplaceAll(old, "\\", "/"))
}
// RelativePath 获取相对可执行文件的路径
func RelativePath(name string) string {
if filepath.IsAbs(name) {
return name
}
e, _ := os.Executable()
return filepath.Join(filepath.Dir(e), name)
}