简体   繁体   English

想要通过批处理文件窗口一次对目录中的每个文件执行命令

[英]Want to execute command on each file in directory one at a time through batch file windows

I am currently doing this to execute a single command on a particular type of files in directory. 我目前正在这样做,以对目录中的特定类型的文件执行单个命令。

COPY *.prn /B \\\\{$PC}\\{$PRINTER}

The PC And Printer Part is redundant no need to understand that PC和打印​​机部件是冗余的,无需理解

Instead of executing all files at once I want to be able to do one file at a time through a loop 我不想一次执行所有文件,而是希望能够通过循环一次执行一个文件

尝试这个:

for %%i in (*.prn) do COPY "%%~i" /B \\\\{$PC}\\{$PRINTER}

Im not entirely sure what you mean but try this, it will execute the command once for each file in the current directory and (all subdirectories, but this exact snipets not ideal for subdirectories) ending with the extension .prn: 我不完全确定你的意思,但试试这个,它将为当前目录中的每个文件执行一次命令(所有子目录,但这个确切的snipets不适合子目录)以扩展名.prn结尾:

for /r %%a in (*) do (
if %%~xa == .prn (
copy %%~na%%~xa /B \\\\{$PC}\\{$PRINTER}
)
)

Tell me if this doesn't work or you want to do this for subdirectories as well. 告诉我,如果这不起作用,或者你想为子目录这样做。

Yours, Mona 你的,莫娜

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM