我花了很多时间试图弄清楚这一点,但我感到非常沮丧。
我想要做的就是查看文件是否存在(确实存在),然后重命名它。我在 Windows 10 的命令行中工作。
IF exist C:\content\info.txt (
ren "C:\content\info.txt" "C:\content\info_new.txt"
) ELSE (
echo "Couldn't find file."
)
Run Code Online (Sandbox Code Playgroud)
我不断收到错误“命令的语法不正确”。我知道该文件存在,因为我之前运行了以下内容。
if exist C:\content\info.txt echo "info.txt is in C:\content\info.txt."
Run Code Online (Sandbox Code Playgroud)
我将所有这些直接输入到命令提示符中,而不是从 .bat 文件中调用它。我在这里错过了什么吗?任何帮助,将不胜感激。