07/07/12
It has been a primary goal of mine for several years to write a Windows program, in either DOS or Perl, to automate changing the folder icon in a batch of subdirectories. It is quite tedious to do this process manually, and when I am trying to customize folder icons this process can eat up hours at a time!
Thus this post is simply to get my frustration down about all the time and effort I put into trying to figure this out and the dearth of knowledge on DOS commands and looping, and the alternative difficulty of doing this in other Windows-friendly languages…. Nature calls … Please let me know if you’ve ever had similar problems?!?
07/08/12
Here are some attempts I made last night to list all subdirectories (folders) in a given folder using the fully-qualified path name. Notice that in batchfoldericon.bat and batchfoldericon2.bat there is a lot of extra code … This is because after 3 hours of research and troubleshooting, I was finally able to get the code to do the variable expansion. But, for some reason it would never write the fully-qualified path to the text file … That or it would be reading the subdirs from one level up … huh? And to top it off, sometimes I’m getting the correct results with the for loop code I have, and other times it is giving me incorrect results as stated earlier!
batchfoldericon.bat
[sourcecode language=”powershell”]
@echo off
REM — File: batchfoldericon.bat
REM — Created: 07/07/12
REM — Author: Eric Hepperle
REM — Notes: %1 refers to the first argument passed to the file.
rem @echo off
REM — THIS WORKS FOR LISTING LEV1 SUBDIRS! 🙂 –>
REM for /d %%X in (%~dp1*) do echo %%X >> c:listjpg.txt
REM for /r %1 %%X in (*.jpg) do (echo %%X >> c:listjpg.txt)
rem SETLOCAL EnableDelayedExpansion
if “%~1” == “.” goto :defaultdircond
if “%~1” == “” goto :defaultdircond
goto :dirpassed
:dirpassed
set %startdir% = %~f1
goto: processdirs
:defaultdircond
echo CONDITION cond was gone-to.
set %startdir% = %cmd%
:processdirs
REM for /d %%X in (%startdir%*) do (
REM echo %%X >> c:listjpg.txt
REM attrib -r “%startdir%*.*” /S /D
REM )
for /d %%X in (%~f1*) do echo %%X >> c:listjpg.txt
REM — THIS WORKS FOR GRABBING ALL LEV1 SUBDIRS AND LISTING
REM — THEIR FULLY QUALIFIED PATHS:
REM — for /d %%X in (%~f1*) do echo %%X >> c:listjpg.txt
[/sourcecode]
batchfoldericon2.bat
[sourcecode language=”powershell”]
@echo off
REM — File: batchfoldericon2.bat
REM — Created: 07/07/12
REM — Author: Eric Hepperle
REM — Notes: %1 refers to the first argument passed to the file.
if “%~1” == “.” goto :defaultdircond
if “%~1” == “” goto :defaultdircond
goto :dirpassed
:dirpassed
set %startdir% = %~f1
goto: processdirs
:defaultdircond
echo CONDITION cond was gone-to.
set %startdir% = %cmd%
:processdirs
for /d %%X in (%startdir%*) do (
echo %%X > c:listjpg.txt
rem @attrib -r “%%X”
)
REM — THIS WORKS FOR GRABBING ALL LEV1 SUBDIRS AND LISTING
REM — THEIR FULLY QUALIFIED PATHS:
REM — for /d %%X in (%~f1*) do echo %%X >> c:listjpg.txt
REM
REM — Get all lev1 subdirs can also be done by:
REM — dir /ad /b
[/sourcecode]
batchfoldericon3.bat
[sourcecode language=”powershell”]
@echo offfor /d %%X in (%~f1*) do echo %%X >> c:listjpg.txt
[/sourcecode]