Sometimes I have a batch file like this:
Action.bat:
Set PATH=%PATH%;C:\Some\Folder\I\Need
foo.exe Bar1
foo.exe Bar2
foo.exe Bar3
@Rem Etc...
where foo.exe is a program that expects PATH to contain a certain directory.
Then I decide to use it for — guess what? — batch processing:
For /R %%f In (*) Do Call Action.bat "%%~f"
Now when I run this, PATH easily overflows.
What is the proper way to prevent this kind of overflow?
Use
SETLOCAL:All the changes to environment variables within the scope of
SETLOCALare, well, local. That is, they are discarded upon executingENDLOCAL.