简体   繁体   中英

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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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