Hope you can help, trying to increment a count inside a for loop.
see below.
for %%F in (%D%) do (
set /a H=%E%
set /a H=%H%+1
echo."AtomicParsley.exe" "%%F" --stik "TV Show" --TVShowName "%T% Season %S%" --TVSeason %S% --TVEpisodeNum %H% --artist "%T% Season %S%" --writeBack>>F:\ipodTvShow\BAT_Scripts\test.txt
)
cannot get the counter VAR=H to increment
any ideas?
Incremental count in a FOR loop
Moderator: DosItHelp
-
- Posts: 40
- Joined: 25 Jan 2008 14:05
Looks like part of a nested for loop? To get variables to evaluate inside a for loop you need to enable delayed expansion and use ! instead of % to indicate the variable to expand when the interpreter gets to it, rather than at the opening of the for statement.
Try something like this.
Try something like this.
Code: Select all
SETLOCAL ENABLEDELAYEDEXPANSION
...
...
...
...
for %%F in (%D%) do (
set /a H=%E%
set /a H=!H!+1
echo."AtomicParsley.exe" "%%F" --stik "TV Show" --TVShowName "%T% Season %S%" --TVSeason %S% --TVEpisodeNum !H! --artist "%T% Season %S%" --writeBack>>F:\ipodTvShow\BAT_Scripts\test.txt
)
Thanks JaffaMuffin
That's sorted it had to take out one of the lines which kept setting H to E, then worked fine.
now looks like.
for %%F in (%D%) do (
set /a E=!E!+1
echo.!E!>>F:\ipodTvShow\BAT_Scripts\test.txt
echo."D:\My Downloads\ipodTvShow\AtomicParsley.exe" "%%F" --stik "TV Show" --TVShowName "%T% Season %S%" --TVSeason %S% --TVEpisodeNum !E! --artist "%T% Season %S%" --writeBack>>F:\ipodTvShow\BAT_Scripts\test.txt
)
now looks like.
for %%F in (%D%) do (
set /a E=!E!+1
echo.!E!>>F:\ipodTvShow\BAT_Scripts\test.txt
echo."D:\My Downloads\ipodTvShow\AtomicParsley.exe" "%%F" --stik "TV Show" --TVShowName "%T% Season %S%" --TVSeason %S% --TVEpisodeNum !E! --artist "%T% Season %S%" --writeBack>>F:\ipodTvShow\BAT_Scripts\test.txt
)
Just a tip:
The "set /a" command can detect variables in a formular so it works without turing on delayed expansion:
or short:
Hope this helps
The "set /a" command can detect variables in a formular so it works without turing on delayed expansion:
Code: Select all
for %%F in (%D%) do (
set /a E=E+1
...
)
or short:
Code: Select all
for %%F in (%D%) do (
set /a E+=1
...
)
Hope this helps
-
- Posts: 40
- Joined: 25 Jan 2008 14:05