Merge directories without overwriting conflicts
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.
Related videos on Youtube
decasteljau
Updated on September 18, 2022Comments
-
decasteljau over 1 year
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?
-
Helder Magalhães about 5 yearsClever 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. 😉