【问题标题】:Creation of files dynamically through a batch file通过批处理文件动态创建文件
【发布时间】:2017-03-01 04:14:50
【问题描述】:

所以我想创建一个批处理文件,它将创建多个 listX.txt,其中每个文件名以动态方式包含 3 个文件名,例如,假设我有 A.txt、B.txt、C.txt 和 D.txt,所需的输出将是两个列表文件,第一个是包含前 3 个 .txt 的 list1.txt,第二个是包含 D.txt 的 list2.txt,可以这样做吗?如何?我目前有这样的东西

for %%i in (*.txt) do (

  ::title
  echo %%~ni>>list.txt
)
PAUSE

它会将它们全部列出到一个文件中,但我不知道如何动态创建多个列表。

【问题讨论】:

    标签: batch-file cmd


    【解决方案1】:

    所以需要统计文件,计算文件数,避免处理新生成的listx.txt文件。

    @Echo off&SetLocal EnableExtensions EnableDelayedExpansion
    Set cnt=0
    for /f "tokens=*" %%i in (
      'Dir /B /ON /A-D *.txt ^|findstr /v /i "list[0-9]*\.txt'
    ) do (
      set /A "cnt+=1,file#=(cnt-1)/3+1"
      ::title
      echo %%~ni>>"list!file#!.txt"
    )
    timeout -1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 2013-08-31
      • 2013-08-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多