Issue
I'm porting some functionality from windows to linux and I'm finding it harder to match the functionality of SHGetKnownFolderPath in linux. Actually there is an API in glib which dose this part but I do not want to use that library here. Also the link does that by exporting variables in .bashrc but I fancy about linux API which does this.
Also the here it is explained like how to access xdg-user-dir. IS there any other way of doing this otherwise I'll stick to this.Please shed some light on this.
Solution
The status of the Linux desktop is a sad mess, especially for this kind of stuff. There are some FreeDesktop standards, but nothing close to Windows Shell APIs for both consistency and commitment to backwards compatibility.
That being said, in my experience the safest thing to do is relying on utilities from XDG, in particular xdg-user-dir
in your case (xdg utils can come in handy in other cases); nowadays they are almost universally installed, and they usually do the "right" thing. Also, many packages rely on them, so it's likely that any DE tests the integration at least on them (IOW: if someone writes configuration that breaks even xdg utils it's likely that they'll fix it; if it's out of spec garbage that happens to work with xdg utils they may not notice).
Please don't try to be too clever with this kind of stuff. Firefox tries to be clever with file associations on Linux and it's 10 years that clicking "open folder" in it opens random applications (for the record, on my box it's extremely fond of opening Gwenview; in the past it liked more FileLight).
Answered By - Matteo Italia Answer Checked By - Marilyn (WPSolving Volunteer)