Spaces in a if statement

2k views Asked by At

I can't seem to get the if statement to work for Hello World. I think it is because of the spaces but any help would be appreciated.

if %A%==Chrome (
    start "" "C:\Users\Matthew\Appdata\Local\Google\Chrome\Application\chrome.exe\"
) else (
    if %A%==Steam (
        start "" "C:\Program Files (x86)\Steam\Steam.exe\"
    ) else (
        if %A%==CMD (
            start
        ) else (
            if %A%==System32 (
                start "" "C:\Windows\System32\"
            ) else (
                if %A%==Appdata (
                    start "" "C:\Users\Matthew\Appdata\"
                ) else (
                    if %A%==Skype (
                        goto Skype
                    ) else (
                        if "%A%"=="Hello World" (
                            goto HelloWorld
                        )
                    )   
                )
            )           
        )
    )
)
1

There are 1 answers

0
MC ND On BEST ANSWER

If the contents of %A% include spaces (Hello world), the first condition will fail as it will be parsed as

if Hello World==Chrome (

If you expect to have spaces in your variable, you will need to use quotes not in the last condition but in all your conditions

if "%A%=="Chrome" (
    start "" "C:\Users\Matthew\Appdata\Local\Google\Chrome\Application\chrome.exe\"
) else if "%A%"=="Steam" (
    start "" "C:\Program Files (x86)\Steam\Steam.exe"
) else if "%A%"=="CMD" (
    start
) else if "%A%"=="System32" (
    start "" "C:\Windows\System32\"
) else if "%A%"=="Appdata" (
    start "" "C:\Users\Matthew\Appdata\"
) else if "%A%"=="Skype" (
    goto Skype
) else if "%A%"=="Hello World" (
    goto HelloWorld
)