Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
141 views
in Technique[技术] by (71.8m points)

Loop through code batch file

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:....Results1
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

question from:https://stackoverflow.com/questions/65874677/how-do-i-loop-something-in-a-batch-file-a-certain-number-of-times

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
@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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...