如何在批处理中进行循环?
我想创建类似这个
dup.bat infile outfile times
示例的用法,
dup.bat a.txt a5.txt 5
它会创建文件 a5.txt,其中 a.txt 的内容重复 5 次
,但是我不知道如何批量执行 for 循环,该怎么做?
I want to create something like this
dup.bat infile outfile times
example usage would be
dup.bat a.txt a5.txt 5
at it would create file a5.txt that has the content of a.txt repeated 5 times
however I do not know how to do for loop in batch, how to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以像这样执行循环:
然后要获取输入文件并重复它,您可以使用带有重定向的
MORE
将输入文件的内容附加到输出文件。请注意,这假设这些是文本文件。You can do the loop like this:
Then to take the input file and repeat it, you could use
MORE
with redirection to append the contents of the input file to the output file. Note this assumes these are text files.For 命令行 args
要执行一个简单的 for 循环,请从
input
文件中读取数据,然后写入output
文件:您也可以不接收输出文件,而是通过命令行执行此操作:
For command line args
To do a simple for loop, read in from the
input
file, and write to theoutput
file:Instead of taking in an output file, you could also do it via command line:
叹息
紧凑的设计:
易于阅读:
设置计数器(次数 = 5)
启动子程序开始
如果您的计数器不等于 0,则读取 a.txt 并将其内容附加到 a5.txt,然后将您的计数器减 1。这将重复五次,直到您的计数器等于 0,然后它将清除您的变量并结束脚本。
SET ENABLEDELAYEDEXPANSION 对于在循环内递增变量非常重要。
sigh
Compact Design:
Easy Reading:
Set your counter (times=5)
Start subroutine Beginning
If your counter doesn't equal 0, read a.txt and APPEND its contents to a5.txt, then decrement your counter by 1. This will repeat five times until your counter equals 0, then it will cleanup your variable and end the script.
SET ENABLEDELAYEDEXPANSION is important to increment variables within loops.