2019-07-12 07:40



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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongxing8009 dongxing8009 2年前

    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"))
    点赞 评论 复制链接分享