英文:
Finding the current working directory programmatically in go?
问题
我已经浏览了Go语言的文档,但目前还没有找到相关内容。我需要帮助来以编程方式找到当前工作目录。有人知道如何做到这一点吗?
英文:
I have been looking trough the go documentation but so far I haven't found anything. I need help to find the current working directory
programmaticly in go language. Does any one know how to do that?
答案1
得分: 8
Getwd 函数来自 os
包,它将返回你当前的工作目录。如果你想要打印它,请按照以下步骤进行操作。
import (
"fmt"
"os"
)
func main() {
wd, _ := os.Getwd()
fmt.Println("当前工作目录:", wd)
}
英文:
Getwd from the os package will return your current working directory. For more operating system related functions look in the os
package.
If you want to print it do the following.
import (
"fmt"
"os"
)
func main() {
wd, _ := os.Getwd()
fmt.Println("Working Directory:", wd)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论