dongxin1999 2018-10-23 06:53
浏览 581
已采纳

Golang在运行和调试时无法获得正确的当前路径?

When I invoke the following code,

 func GetCurrentDirectory() string {
    dir, err := filepath.Abs(filepath.Dir(os.Args[0])) 

it returns:

/private/var/folders/cg/mwzlhrjs5y55ny553g6xz9tr0000gn/T

Absolutely, it is a temp path, I excepted the path is my current directory, not temporary directory.

dir, err := filepath.Abs("")

could help me,but I must judge whether in run、debug mode in goland or not

  • 写回答

2条回答 默认 最新

  • douhao1956 2018-10-23 12:46
    关注

    In order to fix this, go to Run | Edit Configuration... | <name of your configuration> and change the Working Directory property in order to change the working directory of the application or configure the Output directory in order to configure where the binary is created and run from (by default it's in the temporary directory of your OS).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?