1

I wrote a batch script to peruse all png files in a folder and assign them as folder pictures when there's are folders with the same name.

The script works flawlessly when it comes to write the information to desktop.ini files. There's only a small issue: It doesn't work. I can't get the folders to read the modified desktop.ini files and update their pictures.

I'm using Windows 8.1. I suspect I need to delete some sort of cache, but I don't know which and how exactly. From what I've read, when changing folder icons you need to kill explorer.exe, delete iconcache files and restart explorer.exe.

I have no idea whether the iconcache files also store folders pictures, but killing explorer is awful for my workflow anyway. I'd like a process that doesn't require killing tasks if possible.

Below is the script I'm using:

set DriveL=E
set F=desktop.ini
set CatRoot=Media\Textures ^& 3D
set Cat=Nature Shaders
cd "%DriveL%:\%CatRoot%"
for /R %%I  ("%Cat%\*.png") do @(
    if exist %%~dpI%%~nI\ (
        attrib -h -s -r "%~dp0%%~nI\%F%" 2>nul (
            echo [ViewState]
            echo Mode=
            echo Vid=
            echo FolderType=Pictures
            echo Logo=%%~dpI%%~nxI
        ) > "%~dp0%%~nI\%F%"
        attrib +s +h +r "%~dp0%%~nI\%F%"
    )
)
pause
Rhaenys
  • 172
  • 10
  • Possible duplicate of [How can I immediately reload a folder icon when desktop.ini is changed](https://stackoverflow.com/questions/6464147/how-can-i-immediately-reload-a-folder-icon-when-desktop-ini-is-changed) –  Apr 21 '19 at 07:20
  • @LotPings Unfortunately the accepted answer for that question doesn't present a detailed solution, content to point towards a page with a depreciated function for a different version of Windows instead, which doesn't work in Windows 8 and beyond. – Rhaenys Apr 21 '19 at 14:22

1 Answers1

1

You need to tell all explorer windows to update from the newly modified ini file. That is available via the Cscript API

set "DriveL=E:"
set "CatRoot=Media\Textures & 3D"
set "Cat=Nature Shaders"
cd /d "%DriveL%\%CatRoot%"
for /R %%I in ("%Cat%\*.png") do (
     attrib -h -s -r "%temp%\desktop.ini" >nul
         (echo [ViewState]
          echo Mode=
          echo Vid=
          echo FolderType=Pictures
          echo Logo=%%~fI
          ) > "%temp%\desktop.ini"
            attrib +s +h +r "%temp%\desktop.ini"

     (echo set shell = CreateObject^("Shell.Application"^)
      echo set folder = shell.NameSpace^("%%~dpnI"^)
      echo folder.MoveHere "%temp%\desktop.ini", 4+16+1024
     )>"%temp%\folUpd.vbs"
     cscript //nologo //b "%temp%\folUpd.vbs"
  )
)
pause

You have to test and get back to me on this however as I am unable to test this in the device I posted from.

Gerhard
  • 22,678
  • 7
  • 27
  • 43
  • Unfortunately it didn't work. I'll do some reading on this API to see if I can figure it out, given that's my first time working with it. Observation: The `Shell.NameSpace` should point to `%%~dpI%%~nI`, so I changed that in my attempt. It's pointing to the "Cat" folder (Nature Shaders) in your example. – Rhaenys Apr 21 '19 at 15:28
  • no, we are writing to temp and then copy back to path. So don't change the path. Will do a test tomorrow when I am back at home with my laptop. – Gerhard Apr 21 '19 at 15:33
  • First, thanks! Yes, it's copying back to the _parent_ folder path, not the subfolders' I'm altering. So I'm not sure how it would affect the subfolders without being inside them, and it keeps overwriting itself in the final destination anyways. **Example:** Let's say I have `Nature Shaders/Stone 1.png` and `Nature Shaders/Stone 2.png`; plus folders `Nature Shaders/Stone 1/` and `Nature Shaders/Stone 2/`, of which I'm changing the picture to the same-named png files on the parent folder. `desktop.ini` is getting written to `Nature Shaders/` twice instead of to the respective subfolders. – Rhaenys Apr 21 '19 at 16:08
  • P.s.: To make it work you'll also need to remove the _^_ escaping _&_ or the quotes wrapping either the set variables or the cd target. – Rhaenys Apr 21 '19 at 16:17
  • ok, please try it now. I did not know you wanted to affect a folder with the same name as the `png`.. That was what confused me about it. As for the wrapping double quotes on the set variables.. they must be there, do not remove them as they help to eliminate possible unwanted whitespace. I did not notice you had the escape caret, so I removed it. The major change here is `shell.NameSpace^("%%~dpnI"^)` I just added `n` for name so it will complete the folder path `Nature Shaders\Stone 1` – Gerhard Apr 22 '19 at 07:59
  • (1/2) Sorry for being unclear before. First, two minor corrections: Your script is creating `nIfolUpd.vbs` but attempting to run `folUpd.vbs`. I fixed that in my test. It's also missing the if clause but still closing it, so I added it back (`if exist %%~dpnI\ (`). – Rhaenys Apr 22 '19 at 12:06
  • (2/2) It still doesn't work. I might have been unclear in my first comment too, but after the modifications the script worked already: It created a `desktop.ini` at temp, then wrote and executed a vbs, using the shell `MoveHere` function to place `desktop.ini` into the correct subfolders. It didn't refresh the icons. I did run yours anyway, and it doesn't work either. After your post I did some research on this, and what I've found suggests that the win32 shell trick doesn't trigger folder pictures refresh, only icons. – Rhaenys Apr 22 '19 at 12:10