chirag7jain
chirag7jain

Reputation: 1537

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

Upvotes: 0

Views: 115

Answers (2)

Endoro
Endoro

Reputation: 37569

try this:

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

Upvotes: 2

Monacraft
Monacraft

Reputation: 6630

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

Upvotes: 0

Related Questions