Solved Trying to fix default folder icon with batch file and desktop.ini


Bug locker

Well-known member
Member
VIP
Local time
5:45 PM
Posts
379
Location
Athens
OS
Windows 11 Pro
Hey.
I use this tweak in order to change the default order icon. It not works 100% OK.
Depending on the selected view it appears wrong. E.g :

1714931271992.png

1714931867216.png
I noticed though, that when a folder contains a desktop.ini then all folders display correctly in all views.

So , i think to solve that problem (i guess there is no better solution) by put my own desktop.ini at all folders that they dont already have one.
I think that will be done with a batch file and i tried with no success. Unfortunately it's not one of the languages I've dealt with.

The algorithm is simple :
Begining from root (C:)
if the folder not contains desktop.ini
then copy C:\desktop.ini to current folder path
I think the main code is something like that but we need the action in a subroutine.

Code:
@echo off
cd\
FOR /R  %%D IN (*) DO (call :subroutine "%%D")


GOTO :eof


:subroutine

Could anyone with batch language knowledge , translate this algorithm to batch code ?
Also , i there is any suggestion to solve the primary problem please tell me.

Thanks. (y)
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
This would show you which folders do not have desktop.ini files in them. Just replace the echo command at the end with a copy command. No need for jumping around and subroutines.

for /f "tokens=*" %%a in ('dir C:\ /ad /b /s') do @if not exist "%%a\desktop.ini" echo %%a

Note that that code is for a batch file. If running it from a command prompt, replace the double percent symbols with singles.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 [rev. 3737]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical Keyboard with Cherry MX Clears
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical Keyboard - Cherry MX Clear
This would show you which folders do not have desktop.ini files in them. Just replace the echo command at the end with a copy command. No need for jumping around and subroutines.

for /f "tokens=*" %%a in ('dir C:\ /ad /b /s') do @if not exist "%%a\desktop.ini" echo %%a

Note that that code is for a batch file. If running it from a command prompt, replace the double percent symbols with singles.
I run this batch :
Code:
cd\
for /f "tokens=*" %%a in ('dir C:\ /ad /b /s') do @if not exist "%%a\desktop.ini" echo %%a
pause

But its show only that :
1714933799921.png
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
Did you wait for it to finish? It has to loop through all of the directories and check each one before it displays any output. Your screenshot looks like it hasn't finished yet, because I don't see your pause command.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 [rev. 3737]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical Keyboard with Cherry MX Clears
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical Keyboard - Cherry MX Clear
Did you wait for it to finish? It has to loop through all of the directories and check each one before it displays any output. Your screenshot looks like it hasn't finished yet, because I don't see your pause command.
Nope. It looks like its stopped :
1714934623207.png

Think that i already i have folders at root (C:) without desktop.ini in. So it will shows the echo.
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
It won't do any echos until it's finished looping through the directories. This isn't PowerShell.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 [rev. 3737]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical Keyboard with Cherry MX Clears
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical Keyboard - Cherry MX Clear
It won't do any echos until it's finished looping through the directories. This isn't PowerShell.
It looks you have right. I run this and it takes 1 sec.
Code:
REM @echo off
title fix default folder icon
cd\
for /f "tokens=*" %%a in ('dir C:\users\thana\desktop /ad /b /s') do @if not exist "%%a\desktop.ini" echo %%a
pause
With that export :
1714935193111.png

So i go to destination issue.
Code:
for /f "tokens=*" %%a in ('dir C:\users\thana\desktop /ad /b /s') do @if not exist "%%a\desktop.ini" copy c:\desktopinitest.ini %%a
Is that correct ? I use other name in order to delete in case of fault results.
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
That looks good, except I would wrap that last %%a in quotes, in case the path has spaces in it.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 [rev. 3737]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical Keyboard with Cherry MX Clears
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical Keyboard - Cherry MX Clear
That looks good, except I would wrap that last %%a in quotes, in case the path has spaces in it.
Yep you are right. I already taking errors "incorrect syntax" for that reason.
Thanks. (y) ❤️
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
That looks good, except I would wrap that last %%a in quotes, in case the path has spaces in it.
So the current code is :
Code:
REM @echo off
title fix default folder icon
cd\
for /f "tokens=*" %%a in ('dir C:\users\thana\desktop /ad /b /s') do @if not exist "%%a\desktop.ini" copy C:\desktopinitest.txt "%%a"
pause

But still it gives 2 errors :
1714936204662.png
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
Probably some wonky path or something you don't have access to. You could do multiple commands for each directory like this:

Batch:
for /f "tokens=*" %%a in ('dir %USERPROFILE%\Desktop /ad /b /s') do (
REM first command here
REM second command here
REM etc.
)

So then you maybe have an echo for the first command and the copy command for the second command. The echo would show you which folder is having issues.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 [rev. 3737]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical Keyboard with Cherry MX Clears
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical Keyboard - Cherry MX Clear
I run that , and nothing happens except a flashing window for 1 sec :

Code:
@echo off
for /f "tokens=*" %%a in ('dir %USERPROFILE%\Desktop /ad /b /s') do
 (
echo "%%a"
@if not exist "%%a\desktop.ini" copy C:\desktopinitest.txt "%%a"
pause
)

:rolleyes:
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
If you ran it in a command prompt, you'd see that the message is "The syntax of the command is incorrect." Because you moved the ( after do to the next line.
 

My Computers

System One System Two

  • OS
    Windows 11 Pro 23H2 [rev. 3737]
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC12WSHi7
    CPU
    12th Gen Intel Core i7-1260P, 2100 MHz
    Motherboard
    NUC12WSBi7
    Memory
    64 GB
    Graphics Card(s)
    Intel Iris Xe
    Sound Card
    built-in Realtek HD audio
    Monitor(s) Displays
    Dell U3219Q
    Screen Resolution
    3840x2160 @ 60Hz
    Hard Drives
    Samsung SSD 990 PRO 1TB
    Keyboard
    CODE 104-Key Mechanical Keyboard with Cherry MX Clears
  • Operating System
    Linux Mint 21.2 (Cinnamon)
    Computer type
    PC/Desktop
    Manufacturer/Model
    Intel NUC8i5BEH
    CPU
    Intel Core i5-8259U CPU @ 2.30GHz
    Memory
    32 GB
    Graphics card(s)
    Iris Plus 655
    Keyboard
    CODE 104-Key Mechanical Keyboard - Cherry MX Clear
If you ran it in a command prompt, you'd see that the message is "The syntax of the command is incorrect." Because you moved the ( after do to the next line.
Another error:
1714985627377.png

Current code :

Code:
@echo off
for /f "tokens=*" %%a in ('dir %USERPROFILE%\Desktop /ad /b /s') do  (
echo "%%a"
@if not exist "%%a\desktop.ini" copy "C:\Users\thana\Desktop\Recent_pcts\desktop.ini" "%%a"
pause
)

Note : the C:\Users\thana\Desktop\Recent_pcts\desktop.ini has the original attributes System , Archived , Hidden.
 
Last edited:

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
If you ran it in a command prompt, you'd see that the message is "The syntax of the command is incorrect." Because you moved the ( after do to the next line.
So the problem was the attributes. I put at root a desktop.ini with cleared attributes.
At command prompt the copy works. The current code , not works , only a flashing window :

Code:
@echo off
for /f "tokens=*" %%a in ('dir %USERPROFILE%\Desktop /ad /b /s') do  (
echo "%%a"
@if not exist "%%a\desktop.ini"
copy "C:\desktop.ini" "%%a"
attrib +s +h "%%a\desktop.ini"
 pause
)

And command prompt :
1714990689785.png

EDIT : I put () at commands and it looks it works :
Code:
@if not exist "%%a\desktop.ini" (
copy "C:\desktop.ini" "%%a"
attrib +s +h "%%a\desktop.ini" )
:oops:
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
If you ran it in a command prompt, you'd see that the message is "The syntax of the command is incorrect." Because you moved the ( after do to the next line.
So it works , but it has one bug. When the name of the folder contains space ( ) ,
it cant read the name and gives the error :

1714993382294.png
Also i cant underrstand why it shows that path (C:\users\thana\Desktop).

I tried to put "" at %%a , but not works.
Current code :

Code:
@echo off
for /f "tokens=*" %%a in ('dir %USERPROFILE%\Εφαρμογές /ad /b /s') do  (
echo "%%a"
@if not exist "%%a\desktop.ini" (
copy "C:\desktop.ini" "%%a"
attrib +s +h "%%a\desktop.ini" )
 pause
)


EDIT : isn't the cause the space but something else :

1714994044230.png
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus
With this batch script, you can change the Windows 10 or Windows 11 folder icons. You need a folder icon placed next to the batch script and named the folder icon as Blue Folder.ico

Code:
::  Change Windows 10 or Windows 11 folder icons


@Echo Off

Cls & Color 0E

(Net session >nul 2>&1)||(PowerShell start """%~0""" -verb RunAs & Exit /B)


:_CHOICE

Cls & Mode CON  LINES=11 COLS=60 & Color 0E & Title Created By FreeBooter
Echo.
Echo.
Echo.
Echo        1 - Change Windows Folder Icon
Echo.       
Echo        2 - Restore Default Folder Icon
Echo.


Set /p input=:^>

If Not %input%==1 (Goto :_Ex) Else (Goto :_Change)

:_Ex
If Not %input%==2  (Goto :_CHOICE) Else (Goto :_Restore)




:_Change

Cd /d %~dp0

Md c:\blue_folder

Move /Y "Blue Folder.ico"  c:\blue_folder


Reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v "3" /t REG_SZ /d "c:\blue_folder\Blue Folder.ico" /f

Goto :RestartEx






:_Restore



Reg.exe delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons" /v "3" /f







:RestartEx

Taskkill /im Explorer.exe /f

Start Explorer.exe

Exit
 

My Computer

System One

  • OS
    Windows 11
    Computer type
    PC/Desktop
    Manufacturer/Model
    HP Pavilion
    CPU
    AMD Ryzen 7 5700G
    Motherboard
    Erica6
    Memory
    Micron Technology DDR4-3200 16GB
    Graphics Card(s)
    NVIDIA GeForce RTX 3060
    Sound Card
    Realtek ALC671
    Monitor(s) Displays
    Samsung SyncMaster U28E590
    Screen Resolution
    3840 x 2160
    Hard Drives
    SAMSUNG MZVLQ1T0HALB-000H1
Finally it worked. Protected system folders and folders that already have them own icon folder are excluded.
Also so
The code is:

Code:
cls
cd\
@echo off
for /f "tokens=*" %%a in ('dir c: /ad /b /s') do  (
echo "%%a"
@if not exist "%%a\desktop.ini" (
copy "C:\desktop.ini" "%%a"
attrib +s +h "%%a\desktop.ini" )
)
pause

Thanks to pseymor. (y) (y) (y) (y)

1715005153094.png
 

My Computer

System One

  • OS
    Windows 11 Pro
    Computer type
    Laptop
    Manufacturer/Model
    HP Pavilion 17 cd2205nw
    CPU
    Intel 113700H
    Memory
    16GB
    Graphics Card(s)
    NVIDIA RTX 3050 ti
    Screen Resolution
    1980x1020
    Hard Drives
    Micron 512GB
    Mouse
    Logitech
    Internet Speed
    100Mbs
    Browser
    Vivaldi , Edge
    Antivirus
    Norton Plus

Latest Support Threads

Back
Top Bottom