2011-05-19 60 views
0

我現在有這個菜單:批處理文件的幫助(循環和菜單)

echo What would you like to do? 
echo. 
echo Choice 
echo. 
echo 1 Delete File 
echo 2 Ignore File 
echo. 

:choice 
set /P C=[1,2]? 
if "%C%"=="2" goto Deleting 
if "%C%"=="1" goto IgnoreFile 
goto choice 

雖然它似乎沒有工作,當我選擇一個選項,例如2它不會轉到這個:IgnoreFile部分,而是將繼續腳本(即繼續執行文件中的下一個命令,進入我的選擇後)

非常thrustrating,我不河畔

+4

,在這裏工作得很好,但要小心:你的if語句和你的菜單不一致(菜單1 ==刪除,如果1 ==忽略) – Mat 2011-05-19 18:23:32

+0

@Mat我相信答案OP的問題。發表它。 – 2011-05-20 06:53:48

回答

1

如果我沒有理解正確的你的問題,你應該做一個結束標記跳過你的腳本序列。

@echo off 
echo What would you like to do? 
echo. 
echo Choice 
echo. 
echo 1 Delete File 
echo 2 Ignore File 
echo. 

:choice 
set /P C=[1,2]? 
if "%C%"=="1" goto Deleting 
if "%C%"=="2" goto IgnoreFile 
goto choice 


:Deleting 
echo Deleting 
[your code] 
goto end 

:IgnoreFile 
echo IgnoreFile 
[your code] 
goto end 

:end 

每個案例結尾處的「goto end」允許您跳過腳本的剩餘部分。不要忘記在腳本的最後一行製作一個「:end」部分。

如果不使用「轉到結束」,並選擇「刪除」的情況下,刪除部將被執行,並且腳本會一直下去,然後運行「IgnoreFile」案

+0

「goto:end」不需要腳本末尾的現有「:END」標籤。如果存在的話,它會按照預期跳到它。如果沒有,腳本將會停止,就像「exit/b」 – Jay 2012-01-13 13:47:26