1

My goal is to set %PF% variable to C:\ProgramFiles(x86)\MSBuild\ on x64 machines and to C:\ProgramFiles\MSBuild\ on x86 machines. I can easily achieve that such way

IF DEFINED ProgramFiles(x86) SET PF=%ProgramFiles(x86)%\MSBuild\
IF NOT DEFINED ProgramFiles(x86) SET PF=%ProgramFiles%\MSBuild\

But I want to do that in a single IF ELSE statement.

That one

IF DEFINED ProgramFiles(x86) (SET PF=%ProgramFiles(x86)%\MSBuild\) ELSE (SET PF=%ProgramFiles%\MSBuild\)

fails with unexpected "\MSBuild\" error.

That one

IF DEFINED ProgramFiles(x86) (SET PF="%ProgramFiles(x86)%\MSBuild\") ELSE (SET "PF=%ProgramFiles%\MSBuild\")

runs without errors.

But the result value is not what I need ("%ProgramFiles(x86)%\MSBuild\" - instead of "C:\ProgramFiles(x86)\MSBuild\" on x64 machine for example).

So is that possibe?

2
  • 1
    Currently you can solve your problem with the answer of Stephan, but when you embedd your code into a code block you should also read SO: What syntax will check if a variable name containing spaces is defined?, as you will get problems with the closing bracket in if defined ProgramFiles(x86) Commented Aug 11, 2015 at 9:07
  • Thx for that information Commented Aug 12, 2015 at 7:48

1 Answer 1

2

use this syntax:

SET "PF=%ProgramFiles(x86)%\MSBuild\"

Note the position of the quotes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.