MacMost Now 148: Merging Folders

Gary Rosenzweig takes a look at three methods of merging files inside of folders. You can use Apple's FileMerge that comes with XCode, the 'ditto' command in Terminal or a variety of downloadable programs including File Synchronization.
Video Transcript / Captions
Closed captioning for this video is available on YouTube: MacMost Now 148: Merging Folders.

Hi. This is Gary with Today let's look at different methods for merging folders full of files in Mac OS 10. If there's one way that Windows has Mac OS 10 beat, it's in folder merging. This is when you take a folder and drag and drop it onto another folder. In Windows, it'll merge the two folders. It'll save the newest copy of files with the same name, and it will put new files into the merged folder, but it won't delete any old ones. In Mac OS 10, you're simply replacing one folder's contents with the other's, meaning you're deleting any files that weren't in the second folder -- not a merge at all. But there are many different ways to do merges of folders in Mac OS 10. Let's take a look at three such ways. Let's take a look at the test case. I've got two folders here, Test1 and Test2. In Test1 I have four files, Test File 1, 2, 3 and 5. In Test2 I've got four files also, Test File 1, 2, 4 and 5. So there is a file that is missing from here and vice versa, numbers 3 and 4. In addition, Test1/File2 was modified yesterday at 9:00, but in here, Test File 2 was actually modified today. So it's been updated. So this Test File 2 is newer than this Test File 2. Now let's try to merge these together successfully.
There is an official piece of Apple software that will do this. It's called FileMerge. But the catch is that it doesn't come with Mac OS 10. Instead in comes with XCode, which is the developer environment. In order to get the XCode, you have to join the Apple developer community, which is free, and then you have to go over to this part of the Apple site and download XCode, which is a whole gig. Once you've got it, though, you've got a bunch of useful utilities, including FileMerge.
With FileMerge, you get two areas you can compare, left and right. You select what you want for the left comparison, and then you select what you want for the right comparison. Then hit ""compare."" What you'll get is a comparison of everything in those folders. So you get here that Test File 2 is different, 3 is on the left, and 4 is on the right. You can narrow down your results if you have a long list, for instance excluding anything that's identical. Then you select all the files if you want to do a merge. You select what kind of merge, Combine Files, Use left as predominant, right as predominant, etc. Once you've selected the type of merge that you want to do, you select it. It'll ask you what you want to do -- use the existing directory or create a new one. Let's create a new directory at the Test level. We'll call it Test3, and we'll save. The important thing was that I selected all the files on the left. If I had only selected some, it would only have merged those. It's important to remember to do that extra step. Now we look in the Test directory and see that there is, indeed, Test 3, and we see that all the different files are there, including the updated version of Test File 2. And we see the rest, merged together in that one directory. So using FileMerge is pretty difficult if you're not used to programming. There are a lot of different options, and it doesn't always work completely as you'd expect, so it takes some time getting used to. It's not a very automated solution, either.
Now let's look at how we can use the terminal to merge two folders together. We're going to use a command called ""ditto."" This will merge two folders together, and it's pretty easy to use. The first thing you want to do is navigate in terminal to the current directory. Test1 and Test2 are in a directory called ""Test."" An easy way to get there without figuring out exactly where that is, is to select it, and copy. Then we go over to the terminal, and we type ""cd"" for change directory, and then we paste the full path in there. Now we are in that test directory. If we do ""ls"" for list, we look and see, there's Test1 and Test2. Now we're ready to go. What ditto will do is merge two or more directories together, and put them in a third, if you like. For instance, let's do Test1 and Test2, and put them in Test3. And instantly we see that, not only did the command complete in the terminal window, but it created that folder. If we look at Test3, we can see all five files in there. Now let's go and take a look. Of course, 3 and 4 are one from each of the directories, and 2 is actually updated today. And you could see that that's the current file, if we looked into it, rather than the old file. Now if we delete Test3 and reverse the ditto command, we'll see something different as a result. Test2 Test1 Test3. We get the five files just as before, but if we look at File 2, we see that it's the old one. So what ditto is doing is saying, grab the first folder, and then grab the second folder, and this is the one that supersedes the first one. When we do the opposite, Test1 supersedes the second one, so we end up with the old file. This isn't as useful as determining which ones are exactly the newest, but at least you do have this sort of control over it. You can also merge two folders into one, by simply only having two directories there. For instance, ""ditto Test1 Test2"" will merge the contents and the results will be in Test2. You can also merge a whole bunch of them, and the last one will always be the folder that everything ends up in. If it exists, then the contents of that are also merged. If it doesn't exist, it creates it and puts the merge in that folder.
Now there are a bunch of shareware programs out there that allow you to synchronize and merge folders. They have various prices and they have various features. For just simply merging some together, though, one of the simplest seems to be one called File Synchronization. You can download it here. What File Synchronization does is, it allows you to add a pair of folders, and you can do that by dragging and dropping. We can add Test1 and Test2 like that. And then you can determine what you want to do. You can add all sorts of different options, what to do with orphan files, you can set up automatic synchronization between the two of them, and you can set lots of different preferences. Click the synchronize button, and it will synchronize the two folders. This isn't simply merging two folders into one. This is actually synchronizing both. So if I go back to Test1 and Test2, I find they both have all the files in there now. In addition to that, I find that Test File 2 is now the most recent one in both folders. So it's a true file folder synchronization program, not just a merge. It's worth taking a look at, and it costs about $15. There are a lot of other ones there, that cost anywhere between that and upwards of $30 or even more, that do even more advanced file synchronization.
So there's a look at three different ways that you can merge folders together on Mac. They all fall far short of the Windows way of doing it, which is just so simple and elegant that it becomes way more useful. Hopefully, in future versions of Mac OS 10, we'll get the option to either supersedes do it the old way, by replacing a folder, or doing a merge similar to that used in Windows. Until next time, this is Gary Rosenzweig with MacMost Now.

Show notes: The link to download XCode is You can read all about the Terminal ditto command at this official help page: You can get File Synchronization here:

Comments: 4 Responses to “MacMost Now 148: Merging Folders”

    10 years ago

    Very informative and well presented. Just what I was looking for. Many thanks!

    9 years ago

    But what if the files are the same name? The first two options don’t work. And unfortunately I don’t have enough hard drive space for the 3rd.

    Also what if the files have subfolders? And what if some of those subfolders have the same name, but different contents?

    Can’t an app ask the system to look at two file structures, and merge the individual files in folders that share a name?

      9 years ago

      Not sure how detailed you can get, but in your situation you should also consider the manual route — just do it by hand and make the decisions yourself. It might take longer, but it might be the only way to get the job done right.

    9 years ago

    In my case, I have three folders (backups of music libraries). There are no duplicates within each folder, however when the folders merge there will be some. I am trying the terminal command, merging two of the three folders. It’s taking forever, but seems to be working.

Comments Closed.