keep looping with error in batch file

hi,

i have a simple batch file that does xopy of folders
it contains a for loop
however, one of loop generate error (xcopy generate error when copy to source folder), and then loop is terminated.
i dont understand that, shouldnt loop continue to next loop if previous has error?
how can we skip error and continue looping??
IkelcaAsked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
Well you could move the source folder elsewhere...
or exclude it from your copy.

@echo off
for /f "delims=" %%a in ('dir /b /ad "\\testsrv\abc\0???" ^| find /v "1111"') do (
  xcopy "\\testsrv\abc\1111\srcfolder" "%%a\srcfolder" /S /I /Y /E
  echo copied to %%a
)
pause
0
 
anuragsethCommented:
Try using /C switch with xcopy

/C           Continues copying even if errors occur.
0
 
Steve KnightIT ConsultancyCommented:
Can you show us the batch file please?

Steve
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Steve KnightIT ConsultancyCommented:
If the error is along the lines of "file not found" it should be fine.  Maybe it is to do with the esyntax of that xcopy loop, e.g. missed quotes, brackets etc. which then cause it to drop out of the loop?
0
 
ienaxxxCommented:
Be sure you don't have special chars or spaces in the dir name of the source or dest. folders.

if only spaces, be sure to enclose paths in double-quotes, in the loop.

example:

for /F "usebackq delims=;" %%a IN ("myFolderList") DO (
   xcopy "%%a\*.*" "somewhere\%%a"
)


HTH Bye.
0
 
Paul TomasiCommented:
As suggested by dragon-it, please show us the code which is causing the error.
0
 
IkelcaAuthor Commented:
here is code
i know what causes error,because xcopy is trying to copy to source folder....
but i want to skip that error then continue looping to next loop.
/c does not work, because it's problem with for loop i think
for /d  %%a in (\\testsrv\abc\0???) do (

XCOPY "\\testsrv\abc\1111\srcfolder" "%%a\srcfolder" /S /I /Y /E 
echo copied to %%a
)
pause

Open in new window

0
 
Steve KnightIT ConsultancyCommented:
You'll probably have to change %%a to %%~fa to get the full path in the xcopy and echo line instead of %%a (which with for /f here will just give you the top level dir. name otherwise)
0
 
IkelcaAuthor Commented:
true, i could move source folder to somewhere else, but it is not quite easy to do it every time in my case.
it is easier to just leave it and copy from where it is.(folder size is large)
0
 
IkelcaAuthor Commented:
thanks a lot
very helpful
0
 
Paul TomasiCommented:
I take it the 'srcfolder' subfolder exists in all subfolders of \\testsrv\abc\0???
0
 
Steve KnightIT ConsultancyCommented:
BTW if you add /D to the xcopy line then it will only copy newer files if this is appropriate?

Steve
0
 
Paul TomasiCommented:
Oops! Answered already! Wow! That was a firey one!
0
 
IkelcaAuthor Commented:
not really need /D in my case.
thanks again, amazingly fast answer
0
 
Steve KnightIT ConsultancyCommented:
No problem, ask away... I need the points - 77,000 or so until "genius" in MSDOS area and get back past billprew :-)
0
 
Paul TomasiCommented:
Blimey!

This question was asked at 8:22 and answered at 8:45.

That's pretty fast isn't it? I mean, 23 minutes from open to close...

That shows we're on the ball this time in the morning... well, Steve is for sure....

And, there's truth in the saying "The early bird catches the first worm....". Well, you certainly caught yourself a few worms there Steve....

0
 
Paul TomasiCommented:
No need for points Steve.... I can sell you the T-shirt !!.....
0
 
Steve KnightIT ConsultancyCommented:
Right place, right time Paul.... just popped up on screen before I went off to do something else.

Nah, got plenty of EE shirts... painting, mucking out the garden, kids hair cutting :-)  Would like at least no. 1 spot at some point mind (or at least #2 back again), and MSDOS is frankly only hope of that!

Steve
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.