windows 7批处理脚本 - 如果语句不起作用

时间:2013-05-21 10:08:37

标签: windows if-statement batch-file

cd C:\Users\user1\Desktop

if "%time:~0,1%" == " "
ren 85.txt %time:~1,1%.txt 
else ren 85.txt %time:~o,1%.txt 

pause 

上面的脚本无效,但如果我将以下行放入文件中:

ren 85.txt %time:~1,1%.txt 

它正在运作。

为什么上面的if...else声明不起作用?

2 个答案:

答案 0 :(得分:3)

cd C:\Users\user1\Desktop

if "%time:~0,1%" == " " (
 ren 85.txt %time:~1,1%.txt 
) else (
   ren 85.txt %time:~0,1%.txt 
)

pause 

您需要括号或一行if语句:if "%time:~0,1%" == " " ren 85.txt %time:~1,1%.txt

答案 1 :(得分:3)

o不起作用,请使用0(零)尝试:

cd C:\Users\user1\Desktop

if "%time:~0,1%"==" " (ren 85.txt %time:~1,1%.txt 
) else ren 85.txt %time:~0,1%.txt 

pause