MS-DOS: Writing a simple batch file

In MS-DOS, we can write DOS commands into a file and these commands are invoked when we run the file.

Usually we can enter our command at DOS prompt. Once we enter the command, Operating System will execute the command and display the results on DOS console window.

How do we enter multiple commands at a time? The solution is, write the command into the a file and run it from command prompt. This file what we call is the batch file. And the extension of this file is .bat.

MS-DOS Operating System can understand these .bat files and when we enter the file from command prompt, it automatically executes all the commands mentioned in the file, one after one.

We can even write simple conditional statements to control the execution of the commands in batch file.

Lets take the below example:

I have the requirement to run date, time and dir commands at a time. So, I have placed all these commands into a file “sample.bat”. So, the file looks like below:


Based on your requirement you can add commands, or conditional statements inside the batch file. Once the batch file is ready, enter the batch file name at command prompt and press enter key from keyboard. MS-DOS will start executing the command one by one from batch file.


Leave a Reply