Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getCurrentDirectory问题 #10

Closed
zuosc opened this issue Jul 31, 2018 · 4 comments
Closed

getCurrentDirectory问题 #10

zuosc opened this issue Jul 31, 2018 · 4 comments

Comments

@zuosc
Copy link

zuosc commented Jul 31, 2018

Windows10

我在GoLand IDE中调试和编译。发现用这个方法获得的路径是X:\xxxx\xxx\AppData\Local\Temp路径. 然后去找views的时候就找不到,报错了。

如果使用go build main.go 。然后直接run, 则路径没有问题。

这是什么原因呢,应该怎么解决

@zuosc
Copy link
Author

zuosc commented Jul 31, 2018

Goland运行时,修改main.go getCurrentDirectory方法返回""

刚刚看到这个,,,所以这个没有好办法解决么。。。。。

@wangsongyan
Copy link
Owner

添加getCurrentDirectory方法是为了解决直接运行二进制文件无法找到view的问题,正常情况下返回“”就行

@zuosc zuosc closed this as completed Jul 31, 2018
@zuosc
Copy link
Author

zuosc commented Aug 6, 2018

@wangsongyan

使用GoLand开发的话,修改下Working directory路径为当前项目文件,就解决了这个问题。。。。

@52lemon
Copy link

52lemon commented Jun 30, 2020

`
func getCurrentDirectory() string {
//dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
//if err != nil {
// log.Fatal(err)
//}
//return strings.Replace(dir,"\", "/", -1)
str, _ := os.Getwd()
fmt.Print(str)
return strings.Replace(str,"\", "/", -1)
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants