批处理脚本使用列表中的文件名多次复制文件

问题描述 投票:0回答:1

我正在使用批处理脚本来复制几个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
windows batch-file file-rename file-copying
1个回答
0
投票

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 

fruit.txt:

Apples
Oranges
Grapes
Bananas
Strawberry
© www.soinside.com 2019 - 2024. All rights reserved.