2013-07-22 111 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 
)