As I was browsing through old posts at MakeUseOf Answers the other day, I came across a question that gets asked often. How do you merge duplicate files or folders when you’re using a Windows PC? Linux users have simple tools they can use to quickly compare files, like the diff command for example.
Here at MakeUseOf, we’ve covered lots of apps that merge files, such as Mark’s article on how to merge PDF files, or Saikat’s article on how to merge video files. However, what if you just want to merge documents or folders filled with seemingly duplicate lists of files?
In Windows, the task isn’t quite as simple as it is in Linux, but the need does arise every now and then. Maybe you’ve had two common directories for a long time, and despite all efforts to keep them in sync, they no longer contain the same files. Or maybe you’ve been editing the same document in several locations, and you’re no longer sure which one is the most recent, and you don’t want to lose anything important in any one of the copies? The ability to compare seemingly duplicate files or folders can really come in handy sometimes.
An Open Source application that offers that “diff” functionality to Windows users is a free duplicate files utility called WinMerge. This program will accept three arguments – a file or folder to display on the left, a file or folder to display on the right, and a filter that advanced users can use to manipulate the comparison and merge.
Comparing Two Duplicate Folders
One of the most likely uses for this helpful application is to compare two files that you assume were synced, but maybe, for whatever reason, you’ve started to doubt that the two folders are truly duplicates. The WinMerge duplicate files utility can not only tell you whether the two folders are duplicates, but it can highlight the exact differences so that you can decide what you need to do to make the two folders true duplicates.
To portray how this works with folder contents, I’ve created two test folders that contain identical text and image files, except for two differences inside the folders. Folder number two contains an extra text file and an extra image file. As you can see above, I’ve selected folder1 and folder2 as the head to head comparison. Within seconds of clicking OK, the results were in.
As you can see, WinMerge immediately identified the two discrepancies. MyImage5.bmp and TextDocument4.txt are instantly identified as only existing in the folder on the right, Folder 2. The application even provides the file modification dates so that you can see whether there are even differences in when the files were modified. There are certainly cases where you may have a file with the same name, but one is updated while the other isn’t. This software will identify those differences as well.
Comparing Two Duplicate Files
To perform this experiment, I modified TextDocument1.txt and TextDocument2.txt in Folder2 so that they both contain identical text. Basically, I inserted the first three pages of Moby Dick into each file. Then, I inserted three unique sentences in file one, and one unique sentence in file two. The test is to see whether WinMerge can correctly isolate and identify all three differences between these two files.
Here, I’ve set document1 on the left and document2 on the right. In this case, no filters apply – I wanted to compare both files line for line and word for word.
As you can see above, the application successfully identified every single difference. The line containing the alteration is highlighted, and the alteration itself is further highlighted so that you can quickly scroll across the lines of text and see what the exact differences are. The nice thing about this is that if you’re working on a research paper and you’ve added entire paragraphs to the older copy, while you’re in this left window/right window mode, you can actually edit either document just like you would in any text editor.
Here, I’ve highlighted the unique line in document1 and pasted it into the same line in document2. You could do this for individual lines or entire paragraphs – edit either document however you see fit!
Performing A Merge
While manually going through the comparison results line by line and copying them over to the document of the latest version would certainly work, the software wouldn’t really be called WinMerge if there wasn’t some sort of automated approach to the process. Well, there certainly is. One of the top menu items is “Merge,” and the options under this menu item list everything you’ll need to merge any duplicate files or directories you may have.
The first nine options in this menu are actually what I would call “semi-automatic” merging. You can either use the menu options or the keyboard commands to step through each difference in the files, and then either copy the additional text to the right or the left document, depending which one you want to make your “master” document.
The last two options are actually the fully automated merge. Once you quickly scroll down through the differences in the files and you’re satisfied that you want to keep all of the unique content from one file and move it to the other, just select the file you want to merge to, and choose either “Copy All to Right” or “Copy All to Left.” These options automatically fly down through all differences and modify the master file so that it contains any additional content the other file may have. Once the process is through, your files or folders will once again be identical.
Have you ever had the need to compare or merge two duplicate files or folders? Have you ever tried the WinMerge duplicate files utility? Share your opinions and insight in the comments section below.