Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of point_pleasant
point_pleasant
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lionel MM
Is this for a whole range of files or one file?
Avatar of samiam41

ASKER

@point_pleasant, thanks.  Testing now.

@lionelmm, two, small files.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey BP!  Good to see you again.  I will shift my testing to this as it incorporates the error checking.  Thank you.
Two solid options that I have used in my script thus the split points.  Thank you both for your help!

Follow up questions coming.
Avatar of Bill Prew
Bill Prew

Welcome.

~bp