David Ashe schrieb:
> I am trying to take lines from a file, and split the contents into 4 files,
> first line to the first file, 2nd to the second, etc. but the fifth line
> goes back into the first file. (Actually, just the 4th token, not the whole
> line) I am using a counter (creatively named "counter") to decide where the
> line goes however, I am getting unexpected results. I Expect to get a
> round-robin of VALUE:1, VALUE:2,..., and the final "End Counter" being
> between 1 and 4. However, The Final End Counter is equal to the number of
> lines in the file, and I get VALUE:1, over and over.
>
> It is definitely some kind of scope issue, but I don't know how to fix it.
>
Hello David.
Variables in areas enclosed in parenthes are evaluated by the shell
when entering this area. To overcome this behaviour you have to use
delayedexpansion (see setlocal /? or cmd /?) or when your os is nt4
which doesn't have delayed expansion you can use a call to an
internal sub or a pseudo call with a set or echo statement following.
::CounterMod4.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal EnableDelayedExpansion
set COUNTER=0
for /f "tokens=1-4" %%A in (%1) do (
set /a " COUNTER+=1, Val=(COUNTER-1)%%4+1"
echo VALUE: !Val!
call echo VALUE: %%Val%%
)
echo.End Val : %Val%
echo End Counter: %COUNTER%
::CounterMod4.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::
HTH
--
Gruesse Greetings Saludos Saluti Salutations
Matthias
---------+---------+---------+---------+---------+---------+---------+
|