Files do not have an associated icon per se , unless they are executable and not always (it depends on whether the OS supports this feature or not).
To associate an icon to a specific extension, it is necessary to configure it at the operating system level. In this way when opening any file explorer the chosen extension will be shown with the icon that we have indicated.
How is this configuration performed? It depends on the OS, detail that you do not indicate.
Windows
There are two ways to associate icons. Everything depends on whether the file is associated with a certain program or not. You can find the documentation on this at this link I'll explain the simple way:
You have to create the following entry:
HKEY_CLASSES_ROOT \. [EXTENSION]
And in that entry we create an entry with name DefaultIcon
. In this second entry we modify the record (Default)
so that its value corresponds to the path of the icon:
HKEY_CLASSES_ROOT
.AAA
DefaultIcon
(Default) = [PATH_DEL_FICHERO]
Finally, if we want the changes to be applied instantly you have to call SHChangeNotify()
.
Linux
Original link to this section
You can use xdg-utils from freedesktop.org Portland .
Registration of the icon for a MIME type:
xdg-icon-resource install --context mimetypes --size 48 myicon-file-type.png x-application-mytype
Create the configuration file:
Create a configuration file ( freedesktop Shared MIME documentation ) :
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-mytype">
<comment>A witty comment</comment>
<comment xml:lang="it">Uno Commento</comment>
<glob pattern="*.myapp"/>
</mime-type>
</mime-info>
Installation of the configuration file:
xdg-mime install mytype-mime.xml
These steps allow you to associate an icon to a specific format. You can use xdg-mime default
to associate an application with the MIME type after installing the file < a href="http://portland.freedesktop.org/xdg-utils-1.0/xdg-desktop-menu.html"> .desktop