在下面的脚本中,我试图将文本文件的内容设置为朋友号码。问题是%numb%
没有像我想象的那样递增。知道怎么做吗?我尝试过研究但是我不太了解For Each脚本知道如何在脚本中同时增加一个数字和一个增量数字。谢谢!
@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
答案 0 :(得分:1)
您需要delayed expansion 我也改变了你的计数器并实现了另一种递增方法。
@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