Batch Advanced Commands: setlocal Command The

  
setlocal command is used to initiate localization of environment variables in a batch file. Localization will continue until a matching endlocal command occurs or until the end of the batch file.
Syntax:
setlocal {enableextension丨disableextensions}{enabledelayedexpansion丨disabledelayedexpansion}
Parameters:
enableextension
Enable command extension until a matching endlocal command occurs, regardless of the setting before the setlocal command.
disableextensions
Disable command extensions until a matching endlocal command occurs, regardless of the settings before the setlocal command.
enabledelayedexpansion
Enables delayed environment variable expansion until a matching endlocal command occurs, regardless of the setting before the setlocal command.
disabledelayedexpansion
Disables delayed environment variable expansion until a matching endlocal command occurs, regardless of the setting before the setlocal command.
Example:
You can localize environment variables in a batch file with the following code:
rem *******Begin Comment*******
rem This program starts the Superapp batch program on the network,
rem directs the output to a file,and displays the file
rem in Notepad.
rem *******End Comment*******< Br> @echo off
setlocal
path=g:\\programs\\superapp;%path%
call superapp>c:\\superapp.out
endlocal
start notepad c:\\superapp. Out

Copyright © Windows knowledge All Rights Reserved