1

REALLY need some help! Been trying tirelessly for weeks...

This script will change the attributes of all sub-directories then using the icon located within \Icon of sub-directories will create a relevant Desktop.ini that changes the folder icon and a few other settings (If there is an icon located within \Icon)

@ECHO OFF

CHCP 1252 >NUL

set ICOINI=Desktop.ini

for /D %%d IN (*) do (  
    set "FOLDER=%%d"
    call :write_File FOLDER
)

Pause

:Write_File

setlocal EnableDelayedExpansion

IF NOT EXIST "!FOLDER!\Icon\*.ico" goto :EOF

attrib +a +s "!FOLDER!" /d /s

for %%F in ("!FOLDER!\Icon\*.ico") do (set "ICO=%%~nxF")

IF EXIST "!FOLDER!\%ICOINI%" attrib -a -s -h "!FOLDER!\%ICOINI%"

(
    echo [.ShellClassInfo]
    echo IconResource=!CD:~2!\!FOLDER!\Icon\!ICO!, 0
    echo IconFile=!CD:~2!\!Folder!\Icon\!ICO!
    echo IconIndex=0
    echo InfoTip=!ICO:~0,-4!
    echo.
    echo FolderType=Videos
    echo DefaultDropEffect=4
    echo ConfirmFileOp=1
)>"!FOLDER!\%ICOINI%"

attrib -a +s +h "!FOLDER!\%ICOINI%"

echo !FOLDER!

endlocal

goto :EOF

exit /b

The script works in that it changes the attributes of relevant folders and creates Desktop.ini (Except if there is an exclamation mark!). Though it does not always change the icon of the folder. If I manually change Desktop.ini to "." and then back to Desktop.ini it instantly changes the folder icon. So is there a way of renaming Desktop.ini with attributes in tact?

My current method to resolve this problem was with something along these lines:

echo f | xcopy /Y /Q /H /R "!CD!\!FOLDER!\%ICOINI%" "!CD!\!FOLDER!\Desktoop.ini" /K
del /Q /AHS "!CD!\!FOLDER!\%ICOINI%"
echo f | xcopy /Y /Q /H /R "!CD!\!FOLDER!\Desktoop.ini" "!CD!\!FOLDER!\%ICOINI%" /K
del /Q /AHS "!CD!\!FOLDER!\Desktoop.ini"

This fails, sadly, but I don't know why. (It copies, deletes, copies, and then deletes just fine) just doesn't change the folders icon.

Okay, I have run into this problem numerous times before, and although some of it was to do with my command batch script, this problem does not appear to be. Although I would like some help coming up with a work around (If that is even possible in batch!).

Built on Sin
  • 351
  • 2
  • 6
  • 19
  • Duplicate of Refer http://stackoverflow.com/questions/6464147/how-can-i-immediately-reload-a-folder-icon-when-desktop-ini-is-changed – Pranav Negandhi Aug 01 '13 at 08:02
  • When you rename the ini file, the file manager is aware of the change and I suspect that is why the icon changes at that time. If you change some ini files and restart the filemanager, do the new icons also appear then? If so then it is probably a matter of refreshing the screen (F5 in Explorer). – foxidrive Aug 01 '13 at 09:05
  • @foxidrive No, a simple refresh does not affect the folder icons. Sometimes if you create a new file or folder within the sub-directory it will, but not one hundred percent. – Built on Sin Aug 01 '13 at 10:04
  • @Pranav N. Similar question, yes, but not the same question. I found a manual solution, just asking if there was a way I could automate that solution within the confines of the batch script. Also, when the Desktop.ini is changed the folder icon does not change, not it does change but after a few seconds, although I have not tested for longer than three hours. A few important but subtle differences there! – Built on Sin Aug 01 '13 at 10:09
  • Do they appear if you restart Windows Explorer? – foxidrive Aug 01 '13 at 10:12
  • @foxidrive Something I haven't tried until Endoro's comment below and that works brilliantly (Except at the moment I have two thousand Explorer windows) but yes, that refreshes it! TBH I didn't think to even try it as I thought it would have the same results as F5 does. – Built on Sin Aug 01 '13 at 10:25

1 Answers1

2

Tested with Windows XP (YMMV) and Windows Sysinternals

@echo off &setlocal
pskill explorer
start "" explorer
start "" explorer "%folder%"
Endoro
  • 37,015
  • 8
  • 50
  • 63
  • Will that just launch and then close Windows Explorer? – Built on Sin Aug 01 '13 at 10:12
  • It will close the explorer, relaunch it and show the folder `%folder%`. – Endoro Aug 01 '13 at 10:14
  • Argh! Just had thousands of Explorers open on me! Erm, right PSKILL apparently is not a valid command. :-S – Built on Sin Aug 01 '13 at 10:15
  • Although, it does seem to have worked flawlessly, other than the huge flaw of it not closing the explorer windows! :-P – Built on Sin Aug 01 '13 at 10:16
  • So you should use a `VB`Script or the SendKey funktion of `AutoIt` to send `F5`. – Endoro Aug 01 '13 at 10:18
  • Unfortunatly, I don't know the first thing about VBscript (I barely know batch commands) and the SendKey, I just have no idea. Why does opening new explorers work and F5 doesn't? I have tried F5 before. Also: Is there a way to PM? I just want to thank you. I've asked about twenty questions on here, all basically the same thing. You've answered all of them and they all work incredibly well. So, just wanted to thank you a hell of a lot really, and your time is really appreciated (Especially to an idiot like me :-)). – Built on Sin Aug 01 '13 at 10:23
  • Done a little bit more work and just using Taskkill command to do the same job as pskill. – Built on Sin Aug 01 '13 at 21:02
  • Ah, that is why pskill on mine had problems (Windows 7). Eh well, I got it to work thanks to you. My whole script is basically yours TBH :-P. Just one thing, anyway that my script could include '!' exclamation marks on the icon input? As reading the directories can include them, just not the icon. I think it's due to the calling of the function as opposed to just !ICO! – Built on Sin Aug 01 '13 at 21:53
  • It would be better, to enable `delayed expansion` just before the first `echo` and disable it after the last. – Endoro Aug 01 '13 at 21:57