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
声明不起作用?
答案 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