2015-06-15 63 views
0

我似乎無法讓if語句爲Hello World工作。我認爲這是因爲空間,但任何幫助將不勝感激。if語句中的空格

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 
         ) 
        ) 
       ) 
      )   
     ) 
    ) 
) 

回答

3

如果%A%內容包括空格(Hello world),如果你希望在你的可變空間的首要條件會失敗,因爲它會被解析爲

if Hello World==Chrome (

,您需要使用報價不在最後一個條件,但在所有條件下

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 
) 
+0

非常感謝! –