I am getting some errors in my simple Batch file. The file is meant to copy the file “xyz.4do” to the same directory, then rename the copied file to “abc.4do” and finally move the copied/renamed file to a different folder.
My code is below and I have commented where the errors occur:
@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 uses back slash
\as folder delimiters, not forward slash/. Many commands sort of work with forward slash, but it is not reliable.Simply change your paths at the top to use back slash, and everything should work.
It’s interesting that you asked your question today, because it directly relates to this other question that was posted today: Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?