Loop through code batch file

。_饼干妹妹 提交于 2021-02-04 20:54:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!