SHGetKnownFolderPath equivalent API in Linux

情到浓时终转凉″ 提交于 2019-12-02 09:54:29

问题


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.


回答1:


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).




回答2:


The home directory you can retrieve from the environment variable named HOME. This you can fetch using getenv(). Inside your home directory, there are not so many standardized directories. You have Desktop used by Gnome, KDE and friends for what you have on your desktop. Different apps and applications ends up in directories prefixed with a single ., making default listing of directory content hide them in most applications, example .ssh and .mc .



来源:https://stackoverflow.com/questions/37178010/shgetknownfolderpath-equivalent-api-in-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!