30
votes

I try to use with "else" command but I get the foloowing error:

'else' is not recognized as an internal or external command, operable program or batch file.

My code is:

if "zz"=="TRUE" (
        copy /a zz + /a ee=/a zz
    ) 
    else (
        copy /a e + /a %TMP%=/a e
    )

What the problem?

1
I am not recognizing the language I am afraid (so cannot edit on my own), can you add a tag to attract users who are familiar with it?amit
"else" may not be recognised simply because these are language specific - you don't specify which language, which environment you useGermann Arlington

1 Answers

75
votes

The else needs to be on the same "line" (a) as the if. Remove the new-line before the else like so:

if "zz"=="TRUE" (
    copy /a zz + /a ee=/a zz
) else (
    copy /a e + /a %TMP%=/a e
)

Please also note that "zz"=="TRUE" will never evaluate to true - I suspect you meant "%zz%"=="TRUE"?


(a): This isn't always a good description, though it's what the Microsoft documents use. Same command may have been better, and putting ) and else on a different line breaks it into two commands.