8

I want to have certain folders show a picture I made my own instead of having to use the properties and specifying an *.ico file. Is there a way to use a *.jpg or *.png or *.gif or something like that instead? Or a program / script that allows me to more easily tell that folder to use an image I have.

I don't want to manually convert them because that's tedious to do. I'm planning to do this quite often, as a form of recognition when navigating my folder structure. No, search is not an alternative solution...

3 Answers 3

11

As far as I know, for an icon on Windows you must use an .ico file. Although in Win9x days one could get away by using a renamed .bmp, but they look just terrible next to fancy Aero icons – especially since a typical ICO contains several image sizes with transparency layers.

You can use ImageMagick to convert a PNG image to an ICO file:

convert foo.png foo.ico

or if you have PNGs of several sizes,

convert foo-*.png foo.ico

The other part, making Windows use your icon, is easier:

  1. Create a desktop.ini file in your directory, with the following contents:

    [.ShellClassInfo]
    IconFile=folder.ico
    IconIndex=0
    

    Relative paths for IconFile should be supported; they will also work over the network.

    See this MSDN article for detailed instructions on setting the folder icon programmatically.

  2. Mark the directory as either "Read-only" (preferred) or "System":

    attrib +r Music
    

    Without this, Explorer won't even look for desktop.ini customizations, for performance reasons (as explained in The Old New Thing).

  3. Optionally mark desktop.ini as hidden, so that it won't clutter the file list:

    attrib +h +s desktop.ini
    
5
  • What is step 2 used for? Apr 8, 2012 at 20:06
  • 3
    @TomWijsman: Step 2 is required to tell Windows to actually look for a desktop.ini file – this is a performance optimization (Old New Thing post). Step 3 is optional – I personally just don't like seeing the desktop.ini files scattered everywhere. Apr 8, 2012 at 20:09
  • Thank you for a more accurate answer, as well as a tool that supports multiple file types. :) Apr 8, 2012 at 20:18
  • @StevenPenny: +s has some other side effects, so it's only recommended for real system files/folders. Apr 29, 2013 at 17:03
  • @grawity what I am saying is that attrib +r Music does not work on my system, only attrib +s Music.
    – Zombo
    Apr 29, 2013 at 17:14
2

Nope, .ICO files are used (exclusively) for the Icons of folders (since, well, they're Icons ;) ).

You're best/only bet is to convert the image file(s) to the .ICO format.

Perhaps check out these for some ideas/utilities to make the conversion easier on you:

Personally I like Axialis' IconWorkshop for all my .ICO needs. :)

As for injecting/assigning them without using the Properties, that's a different story, and actually pretty easy.

You can specify it by creating/modifying the desktop.ini (text) file in the folder you wish to apply the icon to. Note: this file is a 'hidden' and 'system' file.

Example desktop.ini:

[.ShellClassInfo]
IconResource=C:\Users\techie007\Documents\myNukeBall.ico,0
2
  • There is a web service png2ico. No any installation is required.
    – crea7or
    Apr 8, 2012 at 19:58
  • This sounds easy to automate with a command-line png2iso (adding that to a right click menu for ease) as well as well as making a file with .\folder.ico instead which I can easy copy / paste and then I make both files hidden. Thank you... Apr 8, 2012 at 20:05
0

Public Sub Change_Folder_Icon()

Dim FSO As Object
Dim folderPath As String, DesktopIni As String

folderPath = "C:\Users\user_name\Desktop\my_folder"

If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
DesktopIni = folderPath & "Desktop.ini"

Set FSO = CreateObject("Scripting.FileSystemObject")

With FSO
    .GetFolder(folderPath).Attributes = System
    
    If .FileExists(DesktopIni) Then .DeleteFile DesktopIni
    
    With .CreateTextFile(DesktopIni, True)
        .WriteLine "[.ShellClassInfo]"
        ' Windows 10 Icons
        '.WriteLine "IconFile=%SystemRoot%\system32\SHELL32.dll"
        '.WriteLine "IconIndex=12"
        
        ' Custom icon
        .WriteLine "IconFile=C:\Users\user_name\Desktop\my_folder\Icon.ico"
        .WriteLine "IconIndex=0"
        .Close
    End With
    
    .GetFile(DesktopIni).Attributes = Hidden
End With

End Sub

2
  • 2
    Might be useful to explain what this does and how to run it rather than just giving a block of vbscript. A more useful script would be one that you right-click on an icon, select "use icon for parent folder" and then it creates the correct ini file and hides both the icon and the ini file.
    – Richard
    Mar 18, 2021 at 16:24
  • 1
    How is this better than the manual methods described in the other answers? Please include reasons to use this as well as some idea of when a macro is appropriate. Mar 18, 2021 at 17:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .