echo off :abc Echo ^ text ^ >> C:/files/text_%random%.txt goto abc
How do I do the
goto only 15 times?
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.Visit Stack Exchange
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
Instead of using
goto multiple times, you should use a
Here, you can specify that the loop should run 15 times.
echo off SETLOCAL ENABLEDELAYEDEXPANSION for /L %%i in (1,1,15) do (Echo ^ text ^ >> C:/files/text_!random!.txt)
%%i will be equivalent to 1, 2, …, but it will not be used inside the loop.
gotostatements, and why your answer is better.
forloop better in this case?).
How do I do the goto only 15 times?
FOR /L %%v in (start, step, end) do *something* will do what you need, but if you like using GOTO for this task, you can first set a variable equal to a start value, then increment (or decrement) it each time the repeated operation is performed, testing each time if it has reached the end value. Note that you can start an
echo off line with the
@ symbol to prevent it being echoed to the console.
@echo off set numval=0 REM you can use a variable or else a magic number in the loop set endval=15 :abc Echo ^ text ^ >> C:/files/text_%random%.txt set /a numval +=1 if %numval% lss %endval% goto abc REM or if %numval% lss 15 goto abc echo Done 15 times
In one line in command line:
@cmd /v /c "for /L %l in (1 1 15)do @Echo ^ text ^ >>"C:/files/text_!random!.txt""