3 個の投稿 / 0 new
最終投稿
#1 2022-01-09 21:31

Tutorial: how to add a custom folder icon that persists when shared to other people!

I just learned how to do this, and I thought it was neat, so I'll document it here.

The short version:

1. Create the image you want to use in place of the default folder icon. It should be square and 256x256 or smaller. It can be a JPG or PNG, whatever. The background of the image should be transparent. Remember that it is going to be extremely small on most people's computers (see bottom image), so don't worry about every last detail.
2. Convert the image into "ICO" format. You can use GIMP or some other image editor software, or you can use https://cloudconvert.com/png-to-ico but remember to change the width and height boxes to the desired size.
3. Put the ICO file inside the folder that you want to change the icon of.
4. Create a new text file with the name "APPLY_CUSTOM_FOLDER_ICON.bat" or something else that ends with ".bat". Copy this content into that file:

@echo off
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This batch file will create "desktop.ini" inside a folder, and set the properties
:: of that folder so that the .ICO file in that folder will be used for the folder
:: icon even if this folder is compressed in ZIP/RAR/7Z/etc and moved to a different
:: system.

:: To use this, click-and-drag the folder onto this batch file.
:: There must be exactly one ICO file in the folder when this script runs, so that I
:: know what file to reference in desktop.ini. After running this script, you can 
:: add more ICO files if you want.
:: Sometimes it takes a little while for the change to take effect, but it always
:: works.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: the "input argument" is the folder that gets dragged onto this
:: if there is no "input argument" then do nothing
if [%1] == [] (
goto:eof
)

:: count how many ICO files are in the folder
set ico_count=0
for /f %%A in ('dir /a-d-h-s /b %1 ^| findstr /I \.ico$') do (
set /a ico_count+=1
set ico_name=%%A
)
if not %ico_count% == 1 (
ECHO ERROR: there must be EXACTLY ONE ".ico" file in this folder. I can see %ico_count%.
pause
goto:eof
)

:: if "desktop.ini" already exists, delete it and re-create it
if exist %1\desktop.ini (
attrib -S -H -R %1\desktop.ini
del %1\desktop.ini
)
:: set the read-only flag for the containing folder (this makes it look for and read desktop.ini)
:: note: the read-only flag doesn't affect folders in the same way it affects files.
:: you can still open/move/delete/rename the folder as normal.
attrib +R %1

:: write the text contents into "desktop.txt"
:: Note: for some stupid reason it is CRITICAL that the file be initially created as
:: "desktop.txt" and then renamed to "desktop.ini".
ECHO [.ShellClassInfo]       >%1\desktop.txt
ECHO ConfirmFileOp=0         >>%1\desktop.txt
ECHO IconResource=%ico_name% >>%1\desktop.txt
ECHO IconIndex=0             >>%1\desktop.txt
ECHO ; This "desktop.ini" file exists to make the custom folder icon persist when moved from system to system. >>%1\desktop.txt

:: rename "desktop.txt" -> "desktop.ini"
move %1\desktop.txt %1\desktop.ini
:: set "desktop.ini" to be hidden, and a system file
attrib +S +H %1\desktop.ini

5. Click and drag the folder that you want to change, drag it onto the batch file you created.
6. You may need to wait a little while for the change to take effect, try refreshing with F5, reopening File Explorer, copy/move the folder to a new location and back to the original, that kind of thing.

Why this works:

If you Google "how to set a custom folder icon in Windows", you will find instructions that tell you to right-click the folder, go through properties menus, and browse to the icon you want. What this actually does is create an invisible file inside the folder called "desktop.ini". Inside that file are various settings for how to display that folder, and how to display the contents of that folder. When you use the Windows menu to change the icon, it writes into desktop.ini with the absolute path of the icon you select, such as IconResource=C:/user/mmd/whatever/thumbnail.ico. Because it uses the absolute path, if you compress the folder in ZIP or RAR and send it to someone else, the file path won't be valid any more.

The secret is, you can use a relative path, such as IconResource=thumbnail.ico, and the system will still work as long as desktop.ini and thumbnail.ico are in the same folder, even when that folder is moved! You just need to manually create or edit the desktop.ini file. That's what this batch script does.

The result looks like this (NSFW):

2022-01-10 08:20

I don't know how much use this has for MMD besides organizing folders, but I'll keep this in mind!

2022-01-10 20:28

or you can just download folderico ...
after installation:

    r-click folder
    Change Folder Icon
    More Icons
    click Load on left side
    click Load Folder Image
    select image from file system
    Apply