如何查找Mac文档路径(与语言无关)
I need to find the documents folder path using golang on MacOS. I can do like this:
docsPath := os.Getenv("HOME") + "/Documents"
But I don't know if "Documents" is a valid solution for other OS languages. What if the Mac is Italian language? Is there a way to find out for sure? Or where can I find the proven information that it is always "Documents"? Sadly I do not have access to any Mac other than English.
我需要在MacOS上使用golang查找文档文件夹路径。 我可以这样: p>
docsPath:= os.Getenv(“ HOME”)+“ / Documents”
code> pre>
但是我不知道“文档”对于其他OS语言是否是有效的解决方案。 如果Mac是意大利语怎么办? 有办法确定吗? 还是在哪里可以找到证明总是“文档”的信息? 遗憾的是,我只能使用英语以外的其他Mac。 p>
div>
MacOS places all user files and folders to /Users/%username%/
, e.g. for me /Users/lisitsky
.
Documents are located at subfolder /Users/username/Documents
. You look at it name in terminal by ls /Users/username/Documents
.
Finder shows localized names for standard folders in your language but uses standard names on system level.
Also you may check os/user
module.
func main() {
usr, _ := user.Current()
dir := usr.HomeDir
fmt.Println(dir, path.Join(dir, "Documents"))
}