I have 2 directories structures (A and B) that normally don't overlap. I want to merge A into B.

The following command will merge the directories:

xcopy A B /E /Y

However, I want to be able to detect conflicts between my 2 directories, and don't overwrite if the file is already at destination (in B). The xcopy will automatically overwrite files. I don't want to be prompted for each conflict (/y). I want to xcopy to return an error on conflict.

The /D option does not work either, because I don't care about the date.

I guess this is not possible with xcopy. Are there other solutions for that?


You could use the ROBOCOPY command to move all files that do not collide with existing files in destination. I've added the /L option that lists the outcome, without actually doing anything. If it works as desired, then simply remove the /L option to actually move the files.

robocopy sourcePath destinationPath /mov /xc /xn /xo /xx /L

The ROBOCOPY command produces a nice log of all actions that it takes. Using the above command, you can detect when files where not moved due to collision by looking at the Files :... line in the summary. If the number copied is less than the total, then there where collisions.

The ROBOCOPY command has many options that make it extremely powerful. Type HELP ROBOCOPY or ROBOCOPY HELP from a command prompt for more info.


Create a file e.g. dummy.txt fill ist with many lines containing N like this


Call XCOPY A B /E /-Y <dummy.txt >output.txt

any line in the outputfile containing a question was a conflicted file which was not overwritten.

  • Clever answer. I'm fond of automating stuff like this, but careful with locales: N[o] isn't applicable everywhere, so this should only be used when active language is known a priori. 😉 – Helder Magalhães May 14 '19 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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