1.5 获取文件路径

package main

import (
	"fmt"
	"os"
	"path/filepath"
)

func main() {
	ex, err := os.Executable()
	if err != nil {
		panic(err)
	}

	// Path to executable file
	fmt.Println("绝对路径: ", ex) // 绝对路径

	// Resolve the direcotry
	// of the executable
	exPath := filepath.Dir(ex)
	fmt.Println("执行的路径,文件所在目录Executable path:" + exPath)

	// Use EvalSymlinks to get
	// the real path.
	realPath, err := filepath.EvalSymlinks(exPath)
	if err != nil {
		panic(err)
	}
	fmt.Println("Symlink evaluated:" + realPath)
}


/*
绝对路径:  /private/var/folders/tw/g0l_2m8s7y5690qqjdsvrzd00000gn/T/___go_build_b_go
执行的路径,文件所在目录Executable path:/private/var/folders/tw/g0l_2m8s7y5690qqjdsvrzd00000gn/T
Symlink evaluated:/private/var/folders/tw/g0l_2m8s7y5690qqjdsvrzd00000gn/T

*/
原文地址:https://www.cnblogs.com/zrdpy/p/8593069.html