COPY command in a batch file

G

Guest

I'm creating a batch file with many different lines that use the COPY command
for each line. If that line encounters an error, I want the batch file to
continue processing the next line and not stop. Right now it stops if it
encounters some error. How do I make it continue to the end?
 
P

Pedro Lerma

Hi ken

I think that you should use xcopy command, for example
xcopy /c
this option is that you need.

if you need more information about some command, only type xcopy /? in you
command console, then you should see more options.



Pedro
 
T

Trevor

I'm creating a batch file with many different lines that use the COPY command
for each line. If that line encounters an error, I want the batch file to
continue processing the next line and not stop. Right now it stops if it
encounters some error. How do I make it continue to the end?
You have to know what type of error it encounters. The next
line should read something like "if errorlevel = ? goto next"
Where "next" is the name of any entry point you want.
The entry point no matter what you call it must be preceded
by a :next (colon)
The error could be errorlevel 0,1,2,3 etc...you need to look
at cmd help or batch file help on google. You see the type of error
is reported by some error level number. There are different kinds.
IE. If the file already existed, or if the file didn't copy correctly,
or was copying over a ready only existing file etc etc.
There are hundreds and hundred of examples in google.
If anything search for "file copy errorlevel" or "batch file
errorlevel".

Good Luck,

Trev
 
P

Pegasus \(MVP\)

Trevor said:
You have to know what type of error it encounters. The next
line should read something like "if errorlevel = ? goto next"
Where "next" is the name of any entry point you want.
The entry point no matter what you call it must be preceded
by a :next (colon)
The error could be errorlevel 0,1,2,3 etc...you need to look
at cmd help or batch file help on google. You see the type of error
is reported by some error level number. There are different kinds.
IE. If the file already existed, or if the file didn't copy correctly,
or was copying over a ready only existing file etc etc.
There are hundreds and hundred of examples in google.
If anything search for "file copy errorlevel" or "batch file
errorlevel".

Good Luck,

Trev

The OP wants the batch file to continue on an error. He
does not want to examine the error condition. As Pedro
observed, he should use the /c switch.
 
T

Trevor

The OP wants the batch file to continue on an error. He
does not want to examine the error condition. As Pedro
observed, he should use the /c switch.
sorry....i thought he wanted the batch to make a decision on the
error.

guess i'll refrain from helping in the future.

Good Luck,

Trev
 
P

Pegasus \(MVP\)

Trevor said:
sorry....i thought he wanted the batch to make a decision on the
error.

guess i'll refrain from helping in the future.

Good Luck,

Trev

This is a forum in which various people offer advice to
the best of their knowledge. Sometimes the advice is
incorrect or it misses its mark. If so then other contributors
will add their own comments, thus preventing the OP
from being misled.

It's happened to me on many occasions that my advice
was incorrect. Invariably my errors were pointed out by
other respondents. Instead of withdrawing from this group
altogether, I chose to learn from my mistakes and apply
the extra knowledge when responding next time.
 
U

Uncle Grumpy

Trevor said:
sorry....i thought he wanted the batch to make a decision on the
error.

guess i'll refrain from helping in the future.

"helping" implies that one is replying to the question that was asked.

While you're refraining from "helping"... learn to READ.

Then reply to what you've read should the urge come upon you to "help".
 
J

Jon

Actually, your response contained the seeds of a better approach. To have
programs march on regardless of any errors that occur, is very primitive
programming practice. A program that has sufficient error handling to
analyse any problems that occur, and provide you with a log of them is far
better.
 
P

Pegasus \(MVP\)

Jon said:
Actually, your response contained the seeds of a better approach. To have
programs march on regardless of any errors that occur, is very primitive
programming practice. A program that has sufficient error handling to
analyse any problems that occur, and provide you with a log of them is far
better.

Good point. In this case I recommend this approach:

@echo off
xcopy /s /d /c c:\abc d:\def\ 1>c:\copy.log 2>&1
if ErrorLevel 1 notepad c:\copy.log

The command will now march on regardless of errors.
However, when errors occur it will give the user the
opportunity to examine the corresponding error messages.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top