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