Purpose:Save a copy of the current disk drive, directory, environment, alias and function lists, and special characters




See also: ENDLOCAL.




SETLOCAL can be used on the command line, in aliases, and in batch files.


SETLOCAL will save :


the default disk drive and directory

the environment,

the alias list

the user-defined function 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 array variables.


For example, this batch file fragment saves everything, removes all aliases so that 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:



unalias *

cdd d:\test

setdos /c~

program ~ echo Done!



SETLOCAL and ENDLOCAL may be nested up to 32 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 can also use SETLOCAL and ENDLOCAL in an alias or at the command line. The maximum nesting level from a command line or alias is 32 levels. Unlike batch files, you are responsible for matching the SETLOCAL / ENDLOCAL calls from an alias or command line; TCC will not perform an automatic ENDLOCAL.


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.