SETLOCAL |
|
| Purpose: | Save a copy of the current disk drive, directory, environment, alias list, and special characters. |
| Format: | SETLOCAL |
See also: ENDLOCAL.
Usage:
SETLOCAL is valid only in batch files. It will save :
| • | the default disk drive and directory |
| • | the environment, |
| • | the alias list |
| • | the special character set (command separator, escape character, parameter character, decimal separator, and thousands separator) |
| • | the SETDOS /X setting |
After using SETLOCAL, you can change the values of any or all of the above, and later restore the original values with an ENDLOCAL command, or just by exiting the batch file.
SETLOCAL does not save the command history or user functions.
For example, this batch file fragment saves everything, removes all aliases so that user aliases will not affect batch file commands, changes the disk and directory, changes the command separator, runs a program, and then restores the original values:
setlocal
unalias *
cdd d:\test
setdos /c~
program ~ echo Done!
endlocal
SETLOCAL and ENDLOCAL may be nested up to 16 levels deep in each batch file. You can also have multiple SETLOCAL / ENDLOCAL pairs within a batch file, and nested batch files can each have their own SETLOCAL / ENDLOCAL pairs.
SETLOCAL does not override the Local Aliases configuration option. Consequently changing aliases inside a SETLOCAL/ENDLOCAL pair affects the definition of aliases of other concurrently executing sessions of TCC.
You cannot use SETLOCAL in an alias or at the command line.
An ENDLOCAL is performed automatically at the end of a batch file, or when returning from a "GOSUB filename". If you invoke one batch file from another without using CALL, the first batch file is terminated, and an automatic ENDLOCAL is performed; the second batch file inherits the settings as they were prior to any SETLOCAL.
You can "export" modified variables from inside a SETLOCAL / ENDLOCAL block. See ENDLOCAL for details.