On some Windows environments (Windows 7 and Windows Vista), I have some scripts running and one of the things those scripts are doing, is trying to copy files. The results of those commands are logged in a logfile.

While looking into that logfile, I've just seen the following result:

The system cannot find the path specified.

This obviously is not very helpful (which file does he try to copy, to which directory, ...), so I would like to replace the existing copy commands by xcopy or other commands (in order to use the xcopy /F flag, which shows all files and directories of the xcopy command), but there is a catch: when I simply replace copy by xcopy then the non-existing directory gets created, which I don't want (and I don't find a xcopy flag to prevent this), so now my question becomes:

Is there a commandline command which tries to copy a file to a directory, which shows the files/directories he's copying but which does not create a destination directory in case it does not exist?

Thanks

  • It's giving information indeed, but so is a normal xcopy without the preceeding echo, in top of that it's also creating the %dest1% directory, which I don't want. – Dominique Aug 31 '16 at 12:32
up vote 1 down vote accepted

I'd script that like

copy %file% %dest% || echo copy of %file% failed>>logfile.log

which logs a message when copy returns an error (errorlevel <> 0).

  • I was looking for some kind of parameter, switch, robocopy example but this will do the trick too. :-) Thanks. – Dominique Aug 29 '16 at 11:19

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.