2013-07-22 108 views
0

我一直在一段代碼的工作試圖讓下面的工作:Windows批處理文件ELSE錯誤

echo Date %dayCnt% day(s) before %DBName%_%CurDate% is %DBName%_%mm%_%dd%_%yyyy:~2,2% 
rem ============================ 
If exist %Destination%%DBName%_%CurDate% (
    echo 1 
    If exist %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% (
    echo 2 
    Echo %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% exists! 
    echo 3 
) ELSE (
    echo 4 
    Echo No %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% here today. Maybe we make one? 
    echo 4 
) ELSE (
    echo 5 
    Echo No %Destination%%DBName%_%CurDate% here 
    echo 6 
)) 

輸出我得到的狀態:

Date 3 day(s) before 31499DB_07_22_13 is 31499DB_07_19_13 
ELSE was unexpected at this time. 

如果我把ELSE (到下一行,我得到的東西接近我想看看當代碼如下所示:

echo Date %dayCnt% day(s) before %DBName%_%CurDate% is %DBName%_%mm%_%dd%_%yyyy:~2,2% 
rem ============================ 
rem dir %Destination%%DBName%_%CurDate% 
If exist %Destination%%DBName%_%CurDate% (
echo 1 
    If exist %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% (
    echo 2 
    Echo %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% exists! 
    echo 3 
) 
    ELSE (
    echo 4 
    Echo No %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% here today. Maybe we make one? 
    echo 4 
) 
ELSE (
echo 5 
Echo No %Destination%%DBName%_%CurDate% here 
echo 6 
)) 

輸出如下所示:

Date 3 day(s) before 31499DB_07_22_13 is 31499DB_07_19_13 
1 
2 
x:31499DB_07_19_13 exists! 
3 
'ELSE' is not recognized as an internal or external command, 
operable program or batch file. 
4 
No x:31499DB_07_19_13 here today. Maybe we make one? 
4 
'ELSE' is not recognized as an internal or external command, 
operable program or batch file. 
5 
No x:31499DB_07_22_13 here 
6 
'))' is not recognized as an internal or external command, 
operable program or batch file. 

我該怎麼辦才能讓這個運行沒有這些錯誤?

非常感謝, 山姆

+1

你有一個ELSE後面的ELSE,沒有任何意義 –

+0

謝謝大家的意見。我試圖嵌套這些IF語句,從而將第二次IF與第一次ELSE與第一次出現的ELSE綁在一起;第一個出現的IF對應於第二個出現的ELSE。順便說一句,謝謝亞歷克斯重新格式化我的消息。我試圖在編輯彈出時清理它:-) – Sam

+0

我通過創建後續的if/else語句找到了解決我的問題的方法。我拿出了嵌套的if語句,我相信我可以通過這種方式使事情發揮作用。再次感謝幫助。 – Sam

回答

0

你缺少一個)

echo Date %dayCnt% day(s) before %DBName%_%CurDate% is %DBName%_%mm%_%dd%_%yyyy:~2,2% 
rem ============================ 
If exist %Destination%%DBName%_%CurDate% (
    echo 1 
    If exist %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% (
     echo 2 
     Echo %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% exists! 
     echo 3 
    ) ELSE (
     echo 4 
     Echo No %Destination%%DBName%_%mm%_%dd%_%yyyy:~2,2% here today. Maybe we make one? 
     echo 4 
    ) 
) ELSE (
    echo 5 
    Echo No %Destination%%DBName%_%CurDate% here 
    echo 6 
)