charles
2005-10-29 15:33:11 UTC
With the following code, setlocal is changing to a target directory then
returning to where it started as if a pushd/popd pair was used. I can't
find any documentation that it should do this (and its driven me crazy
until I thought to include a test in the fragment).
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 ====
returning to where it started as if a pushd/popd pair was used. I can't
find any documentation that it should do this (and its driven me crazy
until I thought to include a test in the fragment).
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 ====