3

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
sazr
  • 24,984
  • 66
  • 194
  • 362

2 Answers2

5

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?

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • changing to back slashes doesn't work though. It still says cannot find the file for the 1st copy command. Also it should be noted that the batch file is executing in a different directory to where xyz.4do is – sazr May 10 '12 at 04:10
0

The COPY command is not a one-argument command, you need both a source and a destination.

You should be able to do with with just one command, by the way:

COPY %file% %endDir%\%newName%

For future batch reference, try this site: http://ss64.com/nt/copy.html

Riking
  • 2,389
  • 1
  • 24
  • 36
  • 1
    Absolutely false claim. The destination argument is optional - it defaults to the current folder. The MicroSoft documentation clearly shows the destination as optional with square brackets around the argument. – dbenham Apr 28 '14 at 11:14
  • @dbenham Gah! Guess it's been too long since I worked with Batch. – Riking Apr 30 '14 at 17:34