?
Solved

keep looping with error in batch file

Posted on 2011-10-11
18
Medium Priority
?
282 Views
Last Modified: 2012-06-27
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??
0
Comment
Question by:Ikelca
  • 7
  • 5
  • 4
  • +2
18 Comments
 
LVL 3

Expert Comment

by:anuragseth
ID: 36947175
Try using /C switch with xcopy

/C           Continues copying even if errors occur.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36947177
Can you show us the batch file please?

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36947181
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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 10

Expert Comment

by:ienaxxx
ID: 36947184
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
 
LVL 11

Expert Comment

by:paultomasi
ID: 36947189
As suggested by dragon-it, please show us the code which is causing the error.
0
 

Author Comment

by:Ikelca
ID: 36947190
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
 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 36947205
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36947214
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
 

Author Comment

by:Ikelca
ID: 36947216
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
 

Author Closing Comment

by:Ikelca
ID: 36947247
thanks a lot
very helpful
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36947257
I take it the 'srcfolder' subfolder exists in all subfolders of \\testsrv\abc\0???
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36947258
BTW if you add /D to the xcopy line then it will only copy newer files if this is appropriate?

Steve
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36947259
Oops! Answered already! Wow! That was a firey one!
0
 

Author Comment

by:Ikelca
ID: 36947276
not really need /D in my case.
thanks again, amazingly fast answer
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36947298
No problem, ask away... I need the points - 77,000 or so until "genius" in MSDOS area and get back past billprew :-)
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36947392
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
 
LVL 11

Expert Comment

by:paultomasi
ID: 36947452
No need for points Steve.... I can sell you the T-shirt !!.....
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36947469
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

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I don't know if many of you have made the great mistake of using the Cisco Thin Client model with the management software VXC. If you have then you are probably more then familiar with the incredibly clunky interface, the numerous work arounds, and …
Utilizing an array to gracefully append to a list of EmailAddresses
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question