xcopy file except if file with same name is already present in dir

Hi EE.  As I continue to build this monster batch file, I want to include code that checks if there is a file in the directory with the same name of the one being copied that the copy aborts and records this error.  This is what I have so far:
if not exist group xcopy \\myserver\nfs\group c:\tools\ /y && (
  ECHO File was copied at %time% >>"%logfile%
) || (
  ECHO File was not copied at %time% >>"%logfile%
)

Open in new window

In the code above, the script does check and skips the xcopy if the file is already in the directory but I would like for that action (file xcopy skipped) to be reported to the %logfile%.

Thank you for your help!
LVL 9
samiam41Asked:
Who is Participating?
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.

point_pleasantCommented:
essentially something like this


if exist {insert file name here} (
    echo to log file  exists
) else (
    xcopy
echo success to log file
)
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
Lionel MMSmall Business IT ConsultantCommented:
Is this for a whole range of files or one file?
0
samiam41Author Commented:
@point_pleasant, thanks.  Testing now.

@lionelmm, two, small files.
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Bill PrewCommented:
If you still want the error checking on the xcopy as you have it now  then I think it might look like this:

if exist group (
  Echo xcopy skipped since file exists >> "%logfile%"
) else (
  xcopy \\myserver\nfs\group c:\tools\ /y && (
    ECHO File was copied at %time% >>"%logfile%"
  ) || (
    ECHO File was not copied at %time% >>"%logfile%"
  )
)

Open in new window

~bp
0
samiam41Author Commented:
Hey BP!  Good to see you again.  I will shift my testing to this as it incorporates the error checking.  Thank you.
0
samiam41Author Commented:
Two solid options that I have used in my script thus the split points.  Thank you both for your help!

Follow up questions coming.
0
samiam41Author Commented:
if you have time, i would appreciate the additional expert eyes on this.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28260502.html
0
Bill PrewCommented:
Welcome.

~bp
0
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 Batch

From novice to tech pro — start learning today.