1

In the below script, I am trying to set the contents of a text file to a friend number. The problem is that %numb% is not incrementing as I thought it would. Any idea how to do that? I tried researching however I do not know enough about For Each scripts to know what to do to have both an incrementing number and a for each in the script. Thanks!

@echo off
set numb=1
for /F "tokens=*" %%A in  (list.txt) do  (
   echo Doing junk with %%A and setting it as friend %numb%
   set Friend%numb%=%%A
    set /a numb=%numb%+1
)
set /a %numb%=%numb%-1   
echo there are %numb% Friends
pause
Mark Deven
  • 550
  • 1
  • 9
  • 21

1 Answers1

1

You need delayed expansion.
I also changed your counter a bit and implemented another method of incrementing.

@echo off
setlocal enabledelayedexpansion
set numb=0
for /F "tokens=*" %%A in  (list.txt) do  (
   set /a numb+=1
   echo Doing junk with %%A and setting it as friend %numb%
   set Friend!numb!=%%A
)
echo there are %numb% Friends:
pause
Stephan
  • 53,940
  • 10
  • 58
  • 91