Sarthak Bansal
Sarthak Bansal

Reputation: 65

running all the batch files in a given directory

I have the following batch script for running all the files in a directory .However this script is an infinite loop and keeps on repeating . is there a way to stop the script when it finishes the last batch file the following is my script

@echo off 
 for /R %%x in (*.bat) do ( 
 call "%%x" 
)
pause

Upvotes: 3

Views: 4588

Answers (2)

Jean-François Fabre
Jean-François Fabre

Reputation: 140188

Since you're including this script in your current directory, it is run with the others: recursive/infinite call.

Either put this script one level up, cd in the directory of the bat files and call it with ..\yourscript.bat

Or you could filter out the current script in your loop:

@echo off 
 for /R %%x in (*.bat) do (
 if not "%%x" == "%~0" call "%%x" 
)

Upvotes: 6

peter
peter

Reputation: 42192

That is because you start the batch in the same folder as all the other batchfiles, move this batch to another folder and adjust the (*.bat) path to (other_folder\*.bat). Another way would be to check if the batch is the same as the one that is executed and skip that one.

Upvotes: 2

Related Questions