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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITEnd-user supportCommented:
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
Qlemo"Batchelor", 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.