Xojo or MBS method to add a custom folder icon to a newly created folder?

Hi Folks,

I’ve been digging for a way to add a custom folder to a newly created folder:

  lfolder = SpecialFolder.Documents.Child("Transfer Logs")
  If lfolder = Nil Or Not lFolder.Exists Then
  End If
Catch e As IOError
End Try

Is there a way to add a folder icon for the three platforms at this point?

I searched the forum for answers to your question, the thing that is for sure is that the method is specific to each OS. For example I found this:

Unable to create custom folder icon with MacOS UTI - Targets / macOS - Xojo Programming Forum

Nothing regarding Windows or Linux.

@Christian_Schmitz Is there a function for that in one of your plug-in ? Thanks

We have setIcon functions.

See folderitem.SetIconMBS

1 Like

@Christian_Schmitz - Hmmm, I can’t find it in the FolderItem documentation for 22.1 …


The Example project is in the MBS-Xojo-Plugins222\Examples\Picture\Icon folder and is called Folderitem Icon Example.xojo_binary_project but it didn’t do what I expected when I tried it on Windows. When I opened a png file it gave me the Photoshop icon. The DropFile to see icon.xojo_binary_project did something similar. It appears to only show the icon of the application that the image file that it was associated with.

When I answer on the go from my iPhone, I can’t look as well as on the MacBook.

See NSWorkspaceMBS class:

  • shared method setIcon(image as NSImageMBS, file as folderitem, flags as Integer = 0) as boolean
  • shared method setIcon(image as NSImageMBS, path as string, flags as Integer = 0) as boolean

For Windows and Linux, you may need to do differently.
e.g. on Windows you can make a shortcut file to the folder and then include an icon.
See WindowsShortCutMBS class.