问题
I have done a batch file to help me doing a measurement but I don't know how to put it in a for-loop to make it for n times and to change the name of the folder in "Results" as it changes in the for loop (here I have 01 but just for one measurement time without for loop).
This is the code that I have done:
@echo off
@set var1=var1.exe
@set var2=C:\...\...\... .txt
@set Results=C:\....\Results\01
Mkdir %Results%
%var1% %var2% %Results%
I tried to use this code:
FOR /L %%A IN (1,1,10) DO (
@echo off
@set var1=var1.exe
@set var2=C:\...\...\... .txt
@set Results=C:\....\Results\%%A
Mkdir %Results%
%var1% %var2% %Results%
)
Unfortunately it didn't work
回答1:
@echo off
FOR /L %%A IN (1,1,10) DO call :doit %%A
goto :eof
:doit
set pad=00%1
set num=%pad:~-2%
@set var1=var1.exe
@set var2=C:\...\...\... .txt
@set Results=C:\....\Results\%num%
Mkdir %Results%
%var1% %var2% %Results%
goto :eof
来源:https://stackoverflow.com/questions/17105538/loop-through-code-batch-file