How to run multiple Batch files

run-multiple-batch-files-simplemsoffice

This batch file code can run multiple batch files from a single folder location or multiple folder locations. Suppose you have a bunch of batch files in ‘Source Folder‘ like below:

unzipfile.bat
runpython.bat
mergefile.bat

          And so on……

And Instead of running one by one, you want to run all batch files automatically.

Then follow the below steps:

Step 1: Create a new Batch File, Open Notepad in your system.

Step 2: Copy the below code in Notepad:

1
2
3
4
5
6
7
REM Executing all batch files

start unzipfile.bat

start runpython.bat

start mergefile.bat

Step 3: Save the Notepad file in “Source Folder” and give any name like “runallbatch.bat“.

Now you can run the batch file and it will execute all the above files in the “Source Folder“.

This batch file will execute all mentioned batch files at the same time. 

 

Note:- If you want to edit a batch file, then right-click on it and select Edit or you can open the batch file in Notepad and after editing you can save it.

To run all batch files simultaneously, then use the below code:

1
2
3
4
5
6
7
REM Executing all batch files

call unzipfile.bat

call runpython.bat

call mergefile.bat

In the call function, batch files will run one by one but it will not wait for the completion of the previous batch file means the second batch file will run in parallel.

To run all batch files one after another, then add pause as below:

1
2
3
4
5
6
7
8
9
10
11
12
13
REM Executing all batch files

call unzipfile.bat

pause

call runpython.bat

pause

call mergefile.bat

pause

To run all available batch files in a folder, use the below code:

1
2
3
4
5
6
7
@echo off

cd /d “C:\Source Folder\”

for %%a in (*.bat) do call “%%a”

pause

And save this as a new batch file in a separate folder. If you save in the same folder, then this will go in an infinite loop because it will run itself then.

How to run batch files in different folders?

If you have multiple batch files but in different folders like below:

C:\Source Folder\unzipfile.bat

C:\Source Folder1\runpython.bat

C:\Source Folder2\mergefile.bat

And so on…

Then copy the below code:

1
2
3
4
5
6
7
REM Executing all batch files

call “C:\Source Folder\unzipfile.bat”

call “C:\Source Folder1\runpython.bat”

call “C:\Source Folder2\mergefile.bat”

or

1
2
3
4
5
6
7
8
9
10
11
cd “C:\Source Folder\”

call unzipfile.bat

cd “C:\Source Folder1\”

call runpython.bat

cd “C:\Source Folder2\”

call mergefile.bat

 

0 Comments

Leave a Comment

Your email address will not be published. Required fields are marked *