Topic : Introduction to batch file & How to write a batch file in Windows OS?



Introduction to Batch File:

A batch file is a computer file containing Instructions that the computer should carry out once the batch file is launched.

The Term batch is from batch processing, meaning Non-interactive execution. Batch file is a kind of script file with .bat, .cmd, .btm file extensions in Operating systems which consists of a series of commands to be executed by the command line interpreter (cmd). When we run a batch file, the commands written in it are executed in the command prompt following a serial fashion.

We all know about window command line interpreter known as command prompt or cmd. CMD takes various commands as input through keyborad and processes them. So, The batch file work like a mediator between we and the command prompt. It save our time to repeat the same commands again and again.

Enough Introduction ! now let's start to learn the basic of batch file and learn how we can write our batch files in window OS. follow the given steps and enjoy your learning with InfoBrother.




»

QUICK SUMMARY:



1

creating batch file:


How to create the batch file - Computer tips & tricks - InfoBrother

Open a text editor such as Notepad. We can use any text editor, But the Most used application is Notepad. Notepad commanly used to convert text files into batch files. use following steps to open Notepad.
Press window button and search for Notepad.
Or, Right click at anywhere and select New › Text Document.




2

Basic batch commands:


Batch files run a series of cmd commands or DOS commands, so the batch commands are similar to DOS commands. Some of the more important commands are:

    ECHO: Displays text on the screen and also used to decide whether or not to display the command itself.
    @ECHO OFF: Echo turn off - This command will make sure that the command themselves are not printed.
    START: Run a file with its default application.
    REM: Used to insert the comments in the program. Anything written after REM will not be executed in the program.
    ASSOC: Used to associates an extension with a file type and displays existing associations, or delete an association.
    CD: Show Current directory or move to different directory.
    CLS: Clear screen.
    COPY: Copy files from one location to other.
    EXIT: Exit the DOC console.
    PAUSE: Pause the process and wait for input to be entered.
    TITLE: Edit the title of the window.
    TYPE: Used to display the content of the file to an output console.
    MKDIR/RMDIR:Create or Remove directories.
    DEL: Delete a file or files.
    HELP: Show the list of all Commands.




3

Writing the batch file.


Writing the Batch File - InfoBrother

To Understand, how to create the batch file, let's write a simple batch command that can read the content of a file and display it to an output console. Open your Notepad and write the given script as it is.


@echo OFF  
TYPE D:\textfile.txt 
pause

Above script read the content of textfile.txt and display it to an output console.




4

Saving the batch file.


Saving the Batch File - InfoBrother

Once we have done with writing script in our batch file, we can proceed with saving it as an executable file. Follow the given steps to save the file.

Click File in the top-left corner of the Notepad window and click save - or simply press Ctrl + S to save the file.
Write file name using .bat extension.
Click Save button to save the batch file.




5

Launch the batch file.


Launching Batch File - InfoBrother

Once we have done with creating and saving the batch file using .bat extension, we can launch the batch file to execute the commands. To lunch the commands, Double click on the batch file short cut and the command prompt window will open quickly, executes all the commands written in batch file, and read the content from text file and display it on cmd prompt window.




Batch file save our time, otherwise, we would invested in typing the same commands again and again. For instance, We can create the batch file that can open multiple programs in just one click. Every day when i turn on my pc, i need to open Browser, a text editor, Adobe photoshop, ms word, File explorer and much more... But now i can open these all applications in just one click using batch file.

Using batch file, we can schedule our window OS to shut donw after a specific amout of time.




You like it? Other May like it too:

PLEASE SHARE








I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother




Advertising

Advertisement