batch-file - 复制、重命名然后移动的批处理命令全部失败

标签 batch-file

我的简单批处理文件中出现一些错误。该文件旨在将文件“xyz.4do”复制到同一目录,然后将复制的文件重命名为“abc.4do”,最后将复制/重命名的文件移动到不同的文件夹。

我的代码在下面,我已经评论了发生错误的地方:

@ECHO off
CLS
SETLOCAL

SET  file=C:/users/xyz/desktop/xyz.4do
SET  newName=abc.4do
SET  endDir=C:/users/abc/desktop

REM Error occurs on below line: "The system cannot find the file specified" but the file exists
COPY %file%
REM Error below: "The syntax of the command is incorrect"
REN  %file% %newName%
REM Error occurs on below line: "The system cannot find the file specified"
MOVE %newName% %endDir%

ECHO.
PAUSE
ENDLOCAL

最佳答案

Windows 使用反斜杠 \ 作为文件夹分隔符,而不是正斜杠 /。许多命令都可以使用正斜杠,但它并不可靠。

只需将顶部的路径更改为使用反斜杠,一切都应该有效。

您今天提出的问题很有趣,因为它与今天发布的另一个问题直接相关:Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?

关于batch-file - 复制、重命名然后移动的批处理命令全部失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527293/

相关文章:

batch-file - 批处理文件 - 检查 %2 是否存在,如果不存在则将其设置为 0

batch-file - 如何替换Windows批处理文件中的子字符串

java - 如何捕获批处理执行的 EXE 返回的数据?

powershell - 启动 PowerShell 时获取 bat 文件以继续

javascript - 从 UI 触发批处理文件

windows - ERRORLEVEL与%ERRORLEVEL%与感叹号ERRORLEVEL感叹号

java - Jenkins 调用批处理文件卡在Windows 7中

windows - 在 FOR 循环中使用什么定界符来读取行?

tomcat - 当用户在 services.msc 中手动启动服务时,在启动 tomcat 服务之前运行批处理文件

batch-file - 批处理 : How to store command output with spaces in variable?