for /l
is your friend:
(for /l
是您的朋友:)
for /l %x in (1, 1, 100) do echo %x
Starts at 1, steps by one, and finishes at 100.
(从1开始,以1为步长,以100为结束。)
Use two %
s if it's in a batch file
(如果在批处理文件中,请使用两个%
s)
for /l %%x in (1, 1, 100) do echo %%x
(which is one of the things I really really hate about windows scripting)
((这是我真正讨厌Windows脚本的事情之一))
If you have multiple commands for each iteration of the loop, do this:
(如果循环的每个迭代都有多个命令,请执行以下操作:)
for /l %x in (1, 1, 100) do (
echo %x
copy %x.txt z:whateveretc
)
or in a batch file
(或在批处理文件中)
for /l %%x in (1, 1, 100) do (
echo %%x
copy %%x.txt z:whateveretc
)
Key:
(键:)
/l
denotes that the for
command will operate in a numerical fashion, rather than operating on a set of files
(/l
表示for
命令将以数字方式操作,而不是对一组文件进行操作)
%x
is the loops variable
(%x
是循环变量)
(starting value, increment of value, end condition[inclusive] )
((起始值,值的增量,结束条件[含]))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…