Is there is a way to change a Windows folder icon using a Perl script?
My intention is to change the ordinary icon of the "xxx_documents" folder to some other icon. I have to run the script in such a way that it takes care for the whole drive.
The drive contains many folders. I have to search for each folder named "documents" (e.g. "xxx_documents" or simply "documents") and change its icon to one from the "%SystemRoot%\system32\SHELL32.dll"
library.
Is that possible in Perl? Thanks to all who help me with this.
You sure can do it with Perl. Windows controls directory icons by use of a hidden system
Dekstop.ini
file in each folder. The contents looks something like this:On Windows XP (and I assume on other systems), icon 41 is a tree. Windows requires this file be explicitly set as a system file for it to work, this means we'll need to dig down into
Win32API::File
to create it:If you run the code above, it should set the icon for the current directory to a tree. You may need to refresh your directory listing before explorer picks up the change.
Now that we have a way to change icons, we can now just walk through a whole drive and change every folder that matches our pattern. We can do this pretty easily with
File::Find
, or one of its alternatives (eg,File::Find::Rule
, orFile::Next
):Unfortunately, I've just discovered that the icon only gets changed if the directory currently has, or once had, an icon... There's clearly an attribute that's being set on the directory itself that causes Windows to look for a
Desktop.ini
file, but I can't for the life of me figure out what it is. As such, the above solution is incomplete; we also need to find and fix the attributes on the directory where we're adding the icon.Paul
1.
2.
To get the icon to refresh, you will have to invoke some SHChangeNotify voodoo (C++ example, but you get the idea):