windows - 如何在批处理中循环?

标签 windows loops batch-file dos

我想创建这样的东西

dup.bat infile outfile times

示例用法是

dup.bat a.txt a5.txt 5

它会创建文件 a5.txt,其中 a.txt 的内容重复了 5 次

但是我不知道如何批量做for循环,怎么办?

最佳答案

你可以这样循环:

SET infile=%1
SET outfile=%2
SET times=%3

FOR /L %%i IN (1,1,%times%) DO (
    REM do what you need here
    ECHO %infile%
    ECHO %outfile%
)

然后获取输入文件并重复它,您可以使用带有重定向的 MORE 将输入文件的内容追加到输出文件。请注意,这假定这些是文本文件。

@ECHO off
SET infile=%1
SET outfile=%2
SET times=%3

IF EXIST %outfile% DEL %outfile%
FOR /L %%i IN (1,1,%times%) DO (
    MORE %infile% >> %outfile%
)

关于windows - 如何在批处理中循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5598955/

相关文章:

java - 并发修改异常 : Why does removing the null in List throw this Exception if it´s not the first variable

windows - 如何从 Windows 批处理文件中的 ECHO 字符串中去除引号?

linux - Git Windows 多用户 - 组权限问题

windows - 是否可以在不在 Windows 上创建用户的情况下检查密码是否有效?

JavaScript 函数有效……但不在 for 循环中

java - java中如何去掉单引号和双引号

batch-file - IAR 命令行工具 "iarbuild"可以全部构建吗?

windows - 尽管我的系统中有可用内存,但仍无法访问 R 中的更多内存

windows - 如何在 Windows 上获取 wsChromeEndpointUrl

c++ - 退出 while 循环,cin。使用 ctrl-Z/ctrl-D 不工作 c++