Posts

How to Write a Batch Program Using For Through Numbers

Image
Batch Program Using For Through Numbers. Step 1: 1.Open Notepad 2.Type your Program 3.Save your file as .bat eg. script.bat Batch Program For Through Numbers @echo off setlocal enabledelayedexpansion goto :main :main setlocal For /L %%A in (0,4,20) do echo %%A endlocal goto :eof Output: 0 4 8 12 16 20 Snaps For Reference:                               

How To write a Batch Program using For through numbers

FOR THROUGH NUMBERS Purpose: Runs a specified command for each file in a set of files. Syntax: For /L %% variable in (Start#,Step#,End#) do Command [Command Parameter] Example: @echo off For /L %%A in (0,4,20) do echo %%A In this command, we specified a start value of 0, a step value of 4, and an end value of 20. When this command is executed, the %%A variable takes the values of 0, 4, 8, 12, 16, and 20, and the Echo command is executed for each of these values. OutPut: 0 4 8 12 16 20

How to use Exit Command in Batch File

EXIT COMMAND Purpose: Quits the CMD.EXE program (command interpreter) or the current batch script. Note: Exit is an internal command if it is executed outside the batch file it close CMD.EXE Syntax: EXIT [/B] [exitCode] Prameters:   /B                specifies to exit the current batch script instead of  CMD.EXE.  If executed from outside a batch script, it  will                            quit CMD.EXE exitCode  specifies a numeric number. if /B is specified, sets  ERRORLEVEL that number. If quitting CMD.EXE, sets the                        process  exit code with that number.

How to Write Your First Batch Script Progarm

Image
First Before Writing the Program.Make sure you follow below procedures. 1.Open Notepad or any text editor  2.Next write your commands on your batch file 3.Then save your batch file as ".bat".For Example "myfirstprogram.bat " 4.Then open CMD and type file name along with your extension My First Program @echo off  Title MY First Batch File echo Hello! echo This is My First Line echo This is MY second Line OutPut : Hello! This is My first Line This is MY second Line Snap:

Command Commands Used In Batch File

Command Commands Used In Batch File Command Description Call Used to call one batch file from within another batch file without stopping the processing of the original batch file. Choice Pauses batch file processing and displays a prompt to the user to choose one of the given options using a specified key. Echo Turns the echo on or off. Also used to display a message. Endlocal Ends the localization of environment variables changed by the Setlocal command. The variables are set back to their original values. For Repeats the processing of a command for each file in a group of files. Goto Directs the batch processing to a specified line identified by a label. After jumping to the specified command line, the processing continues with the next command. If Used to perform conditional processing of commands in a batc...

How to use ENDLOCAL/SETLOCAL

ENDLOCAL/SETLOCAL ENDLOCAL: The Endlocal command ends the localization of environment variables set by the Setlocal command and restores the variables to the values they held before the Setlocal command was used. If you use the Setlocal command but forget to add the Endlocal command, the command interpreter automatically restores the environment variables to the values they held before the Setlocal command was used.This command is not effective when used outside a batch file. SETLOCAL: The Setlocal command starts the localization of environment variables in a batch file.This localization continues until a matching Endlocal command is found.You should use the Setlocal and Endlocal commands only inside a batch file. Outside a batch file or a script file, these commands have no effect. Example: @Echo off Rem This command sets local variables Rem Localization ends when Rem Processing of Mybatch2.bat file is complete Setlocal Path=%path%;C:\Myfiles;...

How to use ECHO Command

ECHO Purpose: Displays messages, or turns command-echoing on or off. Syntax:  ECHO [ON | OFF]                   ECHO [message] Prameters: [ON | OFF]:  Specifies whether to turn off or turn on the command-echoing feature. message     :  Specifies the text you want to display on the screen. Example for ECHO OFF @echo off echo echo This is my first Program echo hello echo Example for ECHO ON: C:\WINDOWS\system32>@echo on C:\WINDOWS\system32>echo this is my first program this is my first program C:\WINDOWS\system32>echo hello hello