Need help with variable substitutions and FOR loop

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Graffic
Posts: 5
Joined: 19 May 2010 14:28

Need help with variable substitutions and FOR loop

#1 Post by Graffic » 19 May 2010 15:16

---
Last edited by Graffic on 08 Jul 2010 16:28, edited 1 time in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help with variable substitutions and FOR loop

#2 Post by aGerman » 19 May 2010 16:01

Lot of stuff.

1st)
To substitude something inside a for loop You can't use the dynamic variables (like %%a). You have to use regular variables and the call trick.
Eg. substitude a by b

Code: Select all

@echo off &setlocal
for %%a in (a1 a2 a3 a4) do (
  set "temp=%%a"
  call set "temp=%%temp:a=b%%"
  call echo %%temp%%
)
pause


2nd)
You should find the subfolder name in %~nx1 so you could combine this to the file name.

Hope that helps
aGerman

Graffic
Posts: 5
Joined: 19 May 2010 14:28

Re: Need help with variable substitutions and FOR loop

#3 Post by Graffic » 19 May 2010 16:18

Please bear with me as I'll need a good bit of hand-holding.. You're referring to the new FOR loop which would enclose the code in STEP 03 and also account for random # of files being processed, right? Forgive me but I don't understand the code you've posted. :(

graf

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help with variable substitutions and FOR loop

#4 Post by aGerman » 19 May 2010 16:31

I see.
But it's 0:30 in Germany and I have to sleep some hours. Tomorrow I will try to understand your entire code. Think I can do some more for you.

Regards
aGerman

Graffic
Posts: 5
Joined: 19 May 2010 14:28

Re: Need help with variable substitutions and FOR loop

#5 Post by Graffic » 19 May 2010 17:42

---
Last edited by Graffic on 08 Jul 2010 16:29, edited 1 time in total.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Need help with variable substitutions and FOR loop

#6 Post by aGerman » 20 May 2010 11:19

I can't try it because I don't have your tools.

Code: Select all

@echo off &setlocal
FOR /R %%D in (.) DO CALL :recursive2 "%%D"
GOTO :eof


:recursive2
FOR %%F IN (%~1\*.tga) DO composite -compose Dst_over -tile pattern:checkerboard -size 10x10 "%%F" "%%~nF.png"

montage *.png -background "transparent" -type TrueColorMatte -geometry 120x120+4+4 -tile 4x3 Grid.png

FOR /f "delims=" %%a IN ('dir /a-d /b *.tga') DO CALL :recursive3 %1 "%%a"

del *.png
del *.tga
GOTO :eof


:recursive3
setlocal
FOR /f "delims=- tokens=1*" %%I in ("%~n2") do set "number=%%J"
IF NOT DEFINED number (
  GOTO uBound12
) ELSE (
  GOTO lBound13
)

:uBound12
convert e:\img_output\IM_RSRC\Header.tga %~2 -append ^
  e:\img_output\IM_RSRC\Backdrop.tga +swap -composite ^
  e:\img_output\IM_RSRC\Copyright_Grid.tga -composite ^
  %~1\%~nx1Sheet.tga
endlocal
GOTO :eof

:lBound13
convert e:\img_output\IM_RSRC\Header.tga %~2 -append ^
  e:\img_output\IM_RSRC\Backdrop.tga +swap -composite ^
  e:\img_output\IM_RSRC\Copyright_Grid.tga -composite ^
  %~1\%~nx1Sheet-%number%.tga
endlocal
GOTO :eof


Regards
aGerman

Post Reply