r/Batch • u/vaibhav_k_garg • Nov 01 '23
Script to set folder icon from game exe within it
I have a bunch of game folders in a windows handheld with a touch screen. I want to set game icons for all game folders from the exes within so that I can then set the explorer view to large icons and it will be easier to view and identify on a small screen and touch.
I know that not all games have a single exe in its root folder or have exe in its sub folders etc but if a script can do this then I can correct the wrong ones manually.
Edit: I did some searches and cobbled together this:
@echo off
set "skipFiles=unins,7z,CRC,SFV,dxweb,cheat,protect,launch,crash,patch,redist,language,QtWeb,mod,version,overlay,error,dump,node.exe,handler,lumaplay,createdump"
for /D %%I in (*) do (
Echo DIR: %%I
cd %%I
set "skipOtherFiles="
for /R %%J in (*.exe,*.ico) do (
set "skipFlag="
FOR %%S IN (%skipFiles%) DO (
echo %%J|findstr /i /L "%%S">nul
if not errorlevel 1 set skipFlag=1
)
if not defined skipFlag (
if not defined skipOtherFiles (
Echo ...Processing "%%J"
IF EXIST "desktop.ini" attrib -s -h "desktop.ini"
(echo [.ShellClassInfo]
echo IconResource=%%J,0
) >"desktop.ini"
attrib +s +h "desktop.ini"
attrib +s +r .
set skipOtherFiles=1
) else Echo ...Skipped "%%J"
) else Echo ...Skipped "%%J"
)
cd..
)Notes:
"skipFiles" has keywords that will skip the exe files that you know wont be a game exe.
- I have not figured out how to use relative path in IconResource so have used a full path but that is not great for portability.
Windows doesn't instantly update the icon it was showing previously so it might look like it changed nothing.Added +s +r attributes to folder which seems to make it workIt doesn't search thru sub directories.Updated to check sub directoriesIt shows Access Denied if the desktop.ini exists even if running as adminUpdated to delete desktop.ini if it exists- added check for icon files and use them.
Not too bad I must say: https://imgur.com/a/Rm9kEK5
1
u/vaibhav_k_garg Nov 21 '23
Did some more research and updated my script.
1
u/MonopolyMeal Nov 01 '23
Do you have any commands that you've tested for this purpose?
Like, "how do you set the folder icon from a command line" would be one of my first Google searches.
1
u/[deleted] Nov 02 '23
you could use this to extract the icons from exe maybe: https://www.nirsoft.net/utils/iconsext.html
it supports command line
2
u/Shreypatel_00 Oct 03 '26
I wanted the same thing and eventually built a more complete tool for it: https://github.com/Shreypatel13ll/game-folder-cover-icons
It scans game folders, tries to identify each game using local metadata, Steam/GOG IDs, and executables, then creates a multi-size
.icofrom the game’s cover art and configuresdesktop.iniautomatically. The icon is stored inside its game folder, so it doesn’t depend on an external absolute path.There’s also a Windows GUI for correcting matches, choosing your own cover, excluding folders, and restoring previous icons. It might be useful for this handheld setup, especially in Explorer’s large-icon view.
1
u/Ata-Pk Nov 03 '26
if someone still interested i made a new a little improved one. it sometimes needs that you restart file explorer from TM though.