Markm0705
Markm0705

Reputation: 1440

FOR loop resume execution after loop complete - DOS (Windows Command line)

With much help from this site's contributor I have coded a FOR loop using DOS commands such that one batch file (Fred) with the FOR command executes a second batch file (Barney) with of other commands to make copies of template file (as follows)

Fred.bat:

REM Call Barney.bat to run the copy file command in Barney three times

for /l %%i in (1,1,3) DO Barney.bat %%i

REM now make another copy
copy wilma3.txt to wilma4.txt

Barney.bat:

REM make %i-th copy of the file fred.txt as wilma%i.txt

copy fred.txt wilma%1.txt

The two files (Fred and Barney) work nicely to create three copies (wilma1.txt, wilma2.txt and wilma3.txt) as desired. However, one the three copies are made the focus does not seem to return to the first batch file (Fred) so the the line 'copy wilma3.txt to wilma4.txt' can be executed? Is there a way to produce this result? Perhaps I should be doing the loop copying in just one batch file rather than two?

Upvotes: 0

Views: 529

Answers (1)

Scott C
Scott C

Reputation: 1660

Yes, you could just do this in one bat file, but I'm assuming this is just an example and you have reasons for wanting to call a 2nd bat. To have the execution of Fred continue after the for loop, you need to use: ...) do call Barney.bat %%i

Upvotes: 3

Related Questions