Solver
Solver

Reputation: 169

CMD: IF statement not workin

If I run this:

IF EXIST "%DRVL%:\Windows\syswow64" (SET "arch=x64") ELSE (SET "arch=x86")

IF "%arch%"=="x86" DO ( ECHO x86 )

IF "%arch%"=="x64" DO ( ECHO x64 )

Than its display this:

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

What I'm doing wrong?

Upvotes: 1

Views: 638

Answers (1)

Jason Faulkner
Jason Faulkner

Reputation: 6558

IF doesn't require DO (FOR does).

Try this:

IF EXIST "%DRVL%:\Windows\syswow64" (SET "arch=x64") ELSE (SET "arch=x86")

IF "%arch%"=="x86" (
  ECHO x86
)

IF "%arch%"=="x64" (
  ECHO x64
)

Formatted slightly different to demonstrate nesting IF conditions:

IF EXIST "%DRVL%:\Windows\syswow64" (
    SET "arch=x64"
) ELSE (
    SET "arch=x86"
)

IF "%arch%"=="x86" (
    ECHO x86
) ELSE (
    IF "%arch%"=="x64" ECHO x64
)

Upvotes: 2

Related Questions