doujilou3903 2019-07-12 07:40
浏览 50
已采纳

如何查找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.

  • 写回答

1条回答 默认 最新

  • dongxing8009 2019-07-12 08:10
    关注

    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"))
     }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥50 汇编语言除法溢出问题
  • ¥65 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波