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;D:\Myscripts
Call Mybatch2.bat
Endlocal


Comments

Popular posts from this blog

How to use DIR Command

How to Write Your First Batch Script Progarm

How to use ECHO Command