Because it seems I cant:
if exist c:\ ( goto :myLabel :mylabel )
) was unexpected at this time.
I can workaround this with subroutine but it's strange.
I have no problems with going to labels outside the IF.
There are two different problems here.
1) A GOTO inside of brackets breaks the bracket context (and stops a FOR-Loop)
if 1==1 ( goto :next echo never reached :next echo After the label ) ELSE ( echo Why I can see this? )
After the label Why I can see this?
As you can see the ELSE isn't effective anymore after invoking the GOTO
2) Labels are a bit strange inside of brackets
Labels in brackets use always two lines
- The primary line is the label, here is also a :: Label allowed
- The secondary line (after a label) must be a VALID statement or and label (but not a :: comment), an empty line or a closing bracket isn't valid here
In the secondary line are also the special characters active like "&|>"
( :NormalLabel & echo this will not be executed :SecondaryLine & echo This will be executed )
As you can see, it's all obvious
..I mean it works with two labels.Thanks a lot :-) .
And it's not so obvious.I still do not understand why with two labels the bracket context works.But anyway it works .
Mix the character & with labels are confusing:
( :Label1 & echo line1 :Label2 & echo line2 )
( :Label1 echo line1 :Label2 echo line2 )
@Carlos - Oooh, that is pure evil. I like it!
Long time ago there was a discussion about labels inside barckets.
Nested for loop recursing directories
SO: windows batch file with goto command not working
And there exists a more evil construct.
for %%a in (1 2 3) DO ( :label1 ^ ::label2 :label3 ::Label4 ^ NeverEver^ (^ AlwaysWorks echo %%a) )
It will show the numbers 1 to 3 (obviously)
Ok the code it's a bit obfuscated, but a little bit fun must be.
Btw. I'm happy that I recover my lost sample, as it's the only known way (for me),
to remove a single token form the beginning of a line.
Last edited by jeb (06 Nov 2012 09:38)