文件 get executable path package main import ( "fmt" "os" "path/filepath" ) func main() { ex, err := os.Executable() if err != nil { panic(err) } exPath := filepath.Dir(ex) fmt.Println(exPath) } 文件夹 isdir func IsDir(fileAddr string) bool { s, err := os.Stat(fileAddr) if err != nil { return false } return s.IsDir() } given path is an existing directory // IsDir returns true if the given path is an existing directory. func IsDir(path string) bool { if pathAbs, err := filepath.Abs(path); err == nil { if fileInfo, err := os.Stat(pathAbs); !os.IsNotExist(err) && fileInfo.IsDir() { return true } } return false }