【问题标题】:Batch script to duplicate a file multiple times using filenames from a list使用列表中的文件名多次复制文件的批处理脚本
【发布时间】:2020-05-21 18:41:03
【问题描述】:

我正在使用批处理脚本来复制几个 PDF 并以不同的文件名输出它们。

到目前为止,我所做的是

SET Template=C:\Temp\template.pdf
copy /y %Template% .\%Class%\Apples_fruits.pdf 
copy /y %Template% .\%Class%\Oranges_fruits.pdf
copy /y %Template% .\%Class%\Grapes_fruits.pdf
copy /y %Template% .\%Class%\Bananas_fruits.pdf
copy /y %Template% .\%Class%\Strawberry_fruits.pdf

我想这样做,而不必每次都输入copy /y 行。我想在 .txt.xlsx 文件中有一个“水果”列表,并批量使用列表中的项目作为文件名。

例如:

Apples_fruits.pdf
Oranges_fruits.pdf
Grapes_fruits.pdf
Bananas_fruits.pdf
Strawberry_fruits.pdf

【问题讨论】:

  • 除了没有定义变量class,我看不出你的代码有什么问题。那么你的问题到底是什么?
  • 您提到了 .txt 和 .xlsx 扩展名。我希望您在复制时不要更改文件扩展名。
  • 对不起,我应该更清楚。我想这样做,而不必每次都输入 copy /y 行。我想在 .txt 或 .xlsx 文件中有一个“水果”列表,并批量使用列表中的项目作为文件名。
  • 你需要一个 for /f 循环来迭代一个文本文件。你想要做的基本上是一个单行。

标签: windows batch-file file-rename file-copying


【解决方案1】:

Windows 10 64 位。

批处理文件和fruit.txt必须在同一目录中。

SET Template=%temp%\template.pdf
SET Class=Class
IF /i not exist %Class% md %Class%
FOR /f "delims=" %%g in ('type fruit.txt') do COPY /y %Template% .\%Class%\%%g_fruits.pdf 

水果.txt:

Apples
Oranges
Grapes
Bananas
Strawberry

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 2014-07-13
    • 2020-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多