Problem with .bat program copying files

I have a .bat program which copies files from one hard drive to another, it reads:

---
@echo off

echo Starting backup process...

xCopy /E/Y C:\BDotAttachments\*.*  E:\BDotDesktopBkp\BDotAttachments

if %errorlevel% gtr 0 (
  echo ERROR [%errorlevel%]: Backup process completed but with error(s).
) else (
  echo Backup process completed successfully.
)

pause
---

But when I run it I get the error attached. Please advice.
Capture.PNG
LVL 1
AleksAsked:
Who is Participating?
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Better to just append a backslash to the target path.
xCopy /E/Y C:\BDotAttachments\*.*  E:\BDotDesktopBkp\BDotAttachments\

Open in new window

Regarding the pause - yes, it is supposed to wait for a key press. But cmd.exe is very picky and sometimes behaves errornous with parens, maybe those in the echo text are confusing it, and that leads to unpredictable results.
I would also change the line to something more simple:
@echo off
setlocal EnableDelayedExpansion
echo Starting backup process...
xcopy /E/Y C:\BDotAttachments\*.*  E:\BDotDesktopBkp\BDotAttachments\ && echo  Backup process completed successfully. || echo ERROR [!errorlevel!]: Backup process completed but with errors.
pause

Open in new window

0
 
NVITCommented:
Add the /i switch so you don't get the prompt and it makes the directory automatically
0
 
AleksAuthor Commented:
thx .. seems to work. isn't 'pause' supposed to keep the window open at the end ?  it closes :$
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.