macOS 101: The Many Ways to Merge Folders on the Mac

One of the shortcomings of the Finder is the lack of options when it comes to managing folders and their content. While there are a few issues that are often mentioned, the one we’re going to address here is how to merge folders that have the same name.

It seems to happen quite often when you have a project you’re working on in two different locations, say at home and at work. Or perhaps you’re working on a project on just one Mac, but you have a folder for the currently active project, and one for the updates you’re planning to perform.

In either case, the goal is to unite the two folders so they contain all of the files found in each one. When there are two files with the same name, you want the most recent version to be used, and the older one to be replaced.

Seems simple enough, but for a long time this type of basic file/folder manipulation was beyond the capabilities of the Mac’s Finder. Of course, there are quite a few third-party utilities that can perform the merge function for you; there are even some Apple utilities that can assist in this undertaking. But we’re going to start with just the Finder we use every day, and try out some of its merging options.

Options When Moving Files
When moving or copying files (we’re primarily going to refer to moving files, though you could also be copying files) from a source folder to a destination folder, there are a number of options for how file merging is performed.

The first option is none at all. If the files you’re moving are unique, that is, the names don’t match any of the files currently in the destination folder, then no merge option is presented, and files are simply moved to their new home in the destination folder.

(The default options for merging files conceal a fourth option that can be accessed under certain conditions.)

When one or more file names in the source folder match one or more file names in the destination folder, then the Finder will present four options in a dialog box for how to merge the files into the destination folder.

Actually, you’ll only see three of the four merge options; the last one is hidden, but we’ll show you how to access it.

Keep Both: When a file name matches, both versions are kept in the destination folder, with the file that came from the source folder having a version number appended to its name. As an example, if both the source and destination folder had a file named ExampleFile, then after the move, the destination folder would contain files named ExampleFile and ExampleFile 1.

Stop: As the name implies, selecting this merge option halts the merge function entirely; no files will be moved from the source and no files in the destination will be replaced.

Replace: Selecting the Replace option will cause any file in the destination folder that has the same name to be replaced by the file from the source folder.

(The Skip option replaces the usual Keep Both button provided there are multiple files being moved and you hold down the option key once the dialog box is presented.)

Skip: This is the hidden option that can be revealed by holding down the option key when the dialog box is present. Skip replaces the Keep Both option and allows you to skip over the currently listed file. This is the same as the Stop function, but only applies to the currently listed file in the dialog box. You can use Skip when you spot a file during the merge process that you didn’t mean to move.

Options When Merging Folders
So far, we’ve looked at the options available when moving one or more files between folders. But there are different options when you find yourself moving folders with identical names into a folder.

In this example, you’re moving a folder into a folder that already has a folder with the same name. That’s a lot of items called folder, so let’s add some names to make it easier to follow along.

In this example, you have two folders named Project X, a super-secret assignment you’ve been working on. You have two folders with the same name because you’ve been working on this project on two different computers, and now you want to merge the two folders into one, keeping the most recent versions of any files they contain, and discarding older versions.

While there are quite a few syncing apps that can do this for you, the Finder can also take care of this basic task.

For the Finder to perform the merge you’ll need a destination folder to hold the merged folders; for this example, we’ll simply call this folder Merged. The two source folders have the same name, Project X, but they’re located in two different locations on your Mac.

Start by moving one of the Project X folders to the Merged folder; either one will do.

Hold down the Option key while you drag the second Project X folder onto the Merged folder.

(When you move a folder to a location that contains a folder with the same name, the Finder will present a number of merging options.)

A dialog box will open, presenting two or three options, depending on the state of the files in each Project X folder:

Stop: This will halt any move process, leaving both folders untouched.

Replace: This will cause the folder already present in the target folder (Merged) to be completely replaced by the one you’re moving.

Merge: This option will combine the contents of both folders, keeping the newest version of files with matching names, and preserving all files with unique names. The end result will be a folder that contains the newest version of each file from the two folders.

Merging Subfolders
When merging folders, any subfolders will also undergo the merge functions, with this caveat: The Finder only offers the merge option if there are changes in the top-level folders. In this example, if the Project X folders are identical, with the same names and modification dates, even though there are changes in one or more subfolders, the option to merge will not be presented.

Because it’s not easy to know if there are changes within subfolders, you can use the Ditto command to perform the merge and ensure that all files are properly copied no matter where they reside.

Use Ditto to Merge
If you find yourself in the situation where only subfolders have changes that need to be merged, you can use the Ditto command from within Terminal. Ditto will perform a recursive merge, starting at the top level of the folder, merging all the files, and then continuing on to each subfolder it encounters. The end result is that all files and subfolders in the two Project X folders will be merged.

(The Ditto command can merge folders and all subfolders they may contain.)

To use Ditto, follow these instructions, once again using Project X as the example:

Launch Terminal, located at /Applications/Utilities/.

In the Terminal window that opens, enter the following after the Terminal prompt:

Ditto source_folder destination_folder

Where source_folder is the pathname to one of the Project X folders, and destination_folder is the pathname to the other Project X folder.

An easy way to enter the pathnames is to open a Finder window and navigate to the location of the first folder, and then drag it onto the Terminal window. Terminal will convert the dragged folder into the pathname for you.

Press the space key once after you drag the first folder into Terminal, and then repeat the process with the second folder, dragging it onto the Terminal window.

Once both folders have been dragged onto the Terminal window, press the return key to execute the Ditto command.

The results of the Ditto merge will be present in the second folder (destination_folder) you dragged to the Terminal window. You can view the results in the Finder.


LEAVE A COMMENT