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

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条)

报告相同问题?

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导