I have 2 folders A and B in Windows, containing a lot of files (there can be subfolders containing files etc..). Some of these files are identical between A and B, but there are some files in A not in B and viceversa, and there are also files in A and B with the same name but modified (in this lats case the file can be more recent in A or viceversa). I would merge the two folders in a folders C that contains all files of A and B, and for the last particolar case keep the file with same name and more recent between A and B. How can i do this via Windows batch?
Thanks to all
CodePudding user response:
xcopy /s/e/d A C
xcopy /s/e/d B C
The /d
switch causes xcopy
to copy only if the source file is missing from the destination or is dated later than the same name in the destination
CodePudding user response:
Use robocopy. Visit https://www.ubackup.com/synchronization/robocopy-two-way-sync-8523.html to see basic operations and command line arguments. It also breaks down how to do a 2-way sync, which is what you are asking for.
It has option to exclude older files that are found in both the source and target (/xo: exclude older files.).
It also has flag for purging deleted files.
You can find other suggestions if you visit Sync two folders using batch file