I'm just wondering whether anyone has noticed it/seen anything similar
before.
(Using windows 2000)
==== begin code ====
@echo off&setlocal
rem Function of (maybe) 2 args: 1 = param, 2 = directory
if x%1 == x set blockset=final &goto ENDA1
2>NUL cd /d %1 && (set blockset=final &goto ENDP)
if %1 == early set blockset=%1 &goto ENDA1
if %1 == middle set blockset=%1 &goto ENDA1
echo Unknown blockset mode, using default=final. &set blockset=final
:ENDA1
if not x%2 == x cd /d %2 || echo Unfound directory, can't CD to %2.
rem if errorlevel 1 echo something else
:ENDP
rem test for file in dir.
dir atools.bat
echo Blockset=%blockset%
==== end code ====
SETLOCAL doesn't change the current folder, but I'd noticed that SETLOCAL
localises the effect of any CD commands in the same way as it localises
environment variable changes, so their effect ceases with the following
ENDLOCAL (or the implied ENDLOCAL at the end of the Batch file).
This applies to nested SETLOCAL commands, too, giving rise to
nesting of CD command effects, thus:
CD C:\InitialFolder
:: C:\InitialFolder is now current
SETLOCAL
CD C:\Folder1
:: C:\Folder1 is now current at SetLocal depth 1
SETLOCAL
CD C:\Folder2
:: C:\Folder2 is now current at SetLocal depth 2
ENDLOCAL
:: C:\Folder1 is once again current now we're back at SetLocal depth 1
ENDLOCAL
:: C:\InitialFolder is now current again with no localisation in force
General idea tested in Win95cmd.exe (Win2000 emulator under
Windows 95/98/ME)
--
William Allen
Free interactive Batch Course http://www.allenware.com/icsw/icswidx.htm
Batch Reference with examples http://www.allenware.com/icsw/icswref.htm
From email address not checked. Contact us at http://www.allenware.com/
Well it's neat that it works the way it does and we can let this little
thread be the documentation that MS never published.