Programmatically set custom folder/directory icon in Linux

元气小坏坏 提交于 2019-12-07 08:10:42

问题


In Linux, can one set a custom icon for a folder/directory as it appears in a desktop/file manager?

For example for Windows Explorer one can set a custom icon in the folder's desktop.ini file?

If so, is there a common mechanism or API function to do this (that is perhaps common among distros/desktops/file managers)?

I would like to do this from a standalone console mode program C++ or perhaps using the desktop API for KDE, gnome etc.. (also Unix CDE and OSX)


回答1:


If you are using the KDE desktop, then simply create a .directory file inside the directory.

E.g. I have a custom icon for my directory named "dev.sparc". I created this using the KDE desktop. All it does is create a file which I can view.

$ cat dev.sparc/.directory
[Desktop Entry]
Icon=applications-engineering

Et voila. That's all there is to it. If you or your users are using Gnome, this will be similar but probably subtly different. Just create an empty directory, use Gnome to set an icon, then $ ls -al in the directory to see what file it created.




回答2:


I was recently trying to do something similar with creating desktop shortcuts on various Linux platforms and found this post.

For more information, see the Desktop Entry Specification from freedesktop.org which describes the standard for desktop and directory shortcuts on KDE and GNOME desktops.




回答3:


There is no standard way to do this across GNOME, KDE, and CDE.



来源:https://stackoverflow.com/questions/1036046/programmatically-set-custom-folder-directory-icon-in-linux

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