OK. This is driving me nuts. . . .
. . .
set retry=0
:_ProcNames
if [%retry%]==[1] GoTo NewName
. . .
:NewName
This code is a fragment of code in a for loop. It was not
set retry=0
if [] == [1] GoTo NewName
I already checked the spacing.
HOWEVER, just to be that much more irritating, when I put the
code fragment (copied from the original) as follows in a separate CMD
file, it works!
set retry=0
:_ProcNames
if [%retry%]==[1] GoTo NewName
echo Not retrying . . .
set retry=1
GoTo _ProcNames
:NewName
echo Processing NEW name . . .
PAUSE
exit
Any idea what is going on??????? Thanks in advance, Alan
I was stumped for a minute until I found a clue. The clue is your
statement that this "code in a for loop"! Then I knew what the
problem is. It is that environment variables are evaluated only once
when the code of a FOR loop is first parsed, unless a special
formulation is employed. This is called 'delayed expansion'. It is
explained in, of all places, the help to the SET statement, though
there is a reference in the SETLOCAL statements help (but not a word
in the help to the FOR):
quote
Delayed environment variable expansion allows you to use a different
character (the exclamation mark) to expand environment variables at
execution time. If delayed variable expansion is enabled, the above
examples could be written as follows to work as intended:
set VAR=before
if "%VAR%" == "before" (
set VAR=after
if "!VAR!" == "after" @echo If you see this, it worked
)
set LIST=
for %i in (*) do set LIST=!LIST! %i
echo %LIST%
end quote
Invoking delayed expansion requires the following rather wordy
statement ...
setlocal enabledelayedexpansion
So try this and see if it doesn't fix things...
setlocal enabledelayedexpansion
for ... in (...) do (...
set retry=0
:_ProcNames
if [!retry!]==[1] GoTo NewName
echo Not retrying . . .
set retry=1
GoTo _ProcNames
:NewName
echo Processing NEW name . . .
)
Tom Lavedas
=========