Finding the current working directory programmatically in go?

huangapple go评论91阅读模式
英文:

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

huangapple
  • 本文由 发表于 2015年3月27日 05:01:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/29288793.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定