2014-10-29 42 views
0

我這裏有這樣的代碼:批處理文件空間用的if else

:a 
set /p unit=Unitpile Entry: 
echo %unit% >> unitpile.txt 
if %unit% EQU exitscript (
goto b 
) else (
goto a 
) 

,每當%單位%中有一個空間,所以這是兩個詞,文件關閉。 請幫忙...或者是語法問題。 順便說一句我有其他所有適當的標籤,這只是這是整個代碼的一個片段。

回答

0

這裏是你的批處理代碼和一些評論。你可以在這裏看到如何使用雙引號。

:a 
rem Define environment variable unit with a double quote as default value. 
set "unit="" 
set /p "unit=Unitpile Entry: " 
rem Remove all double quotes entered by user. If the user has not entered 
rem anything, the default double quote is removed. The default is necessary 
rem in case of user enters nothing to make the next line working also in 
rem this special case. 
set "unit=%unit:"=%" 
rem Has the user entered anything at all? 
if "%unit%"=="" goto :EOF 
echo %unit%>>unitpile.txt 
if /I "%unit%"=="exitscript" (
    goto b 
) else (
    goto a 
) 
:b 
+0

現在正常工作,工作很好,謝謝。 – JustBlu 2014-10-29 10:28:12