Windows批处理文件ELSE错误

时间:2013-07-22 14:30:55

标签: batch-file

我一直在使用一段代码试图让以下内容起作用:

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 个答案:

答案 0 :(得分: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
)