Monday, February 04, 2019

How to Run Multiple Batch Files From a Single Batch File - Step by Step Guide



Suppose you have 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 below steps:

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

Step 2: Copy below code in Notepad:

REM Executing all batch files

start unzipfile.bat
start runpython.bat
start mergefile.bat


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

Now you can run batch file and it will execute all above files in “Source Folder”.
This batch file will execute all mentioned batch files at the same time. 

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


If you want to run all batch files simultaneously, then use below code:

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 completion of previous batch file means second batch file will run in parallel.


If you want to run all batch files one after another, then add “pause” as below:

REM Executing all batch files

call unzipfile.bat
pause
call runpython.bat
pause
call mergefile.bat
pause




How to run all available batch files in a folder from a batch file?

If you want to run all available batch files in a folder, then copy below code:

@echo off
cd /d "C:\Source Folder\"
for %%a in (*.bat) do call "%%a"
pause

And save this as new batch file in separate folder. If you save in same folder, then this will go in 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 below code:

REM Executing all batch files

call “C:\Source Folder\unzipfile.bat”
call “C:\Source Folder1\runpython.bat”
call “C:\Source Folder2\mergefile.bat”

or

cd "C:\Source Folder\"
call unzipfile.bat

cd "C:\Source Folder1\"
call runpython.bat

cd "C:\Source Folder2\"
call mergefile.bat


***** End *****

No comments:

Post a Comment