1

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.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Volker
  • 428
  • 4
  • 15
  • 1
    According to [this](https://discussions.apple.com/thread/3014097), it looks like the directory name is always the same, but the localized version can be configured for display purposes. – Jonathan Hall Jul 12 '19 at 07:44

1 Answers1

3

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"))
 }
Eugene Lisitsky
  • 12,113
  • 5
  • 38
  • 59
  • I don't think this answers the question, which is what is `Documents` called in different languages. – Jonathan Hall Jul 12 '19 at 08:31
  • If I got right, the question was about finding system path of Documents folder. It is is the same on all localized systems and is `/Users/username/Documents` regardless of localization. For example, on one of machines I have Russian locale and my folder is shown as `Документы` in Finder, but system path is the same `~/Documents`. – Eugene Lisitsky Jul 12 '19 at 09:00
  • I would suggest making that point in the answer--that the system path doesn't depend on language. – Jonathan Hall Jul 12 '19 at 09:48