golang获取当前程序所在的目录
可以使用os.Executable()函数来获取当前程序所在的目录。
package main
import (
"fmt"
"os"
"path/filepath"
)
func main() {
ex, err := os.Executable()
if err != nil {
panic(err)
}
dir := filepath.Dir(ex)
fmt.Println("当前程序所在的目录:", dir)
}
输出结果为当前程序所在的目录。
原文地址: https://www.cveoy.top/t/topic/ivXw 著作权归作者所有。请勿转载和采集!