Ledge

How to move files out of subfolders into one folder on a Mac

Finder can do this on its own: search inside the parent folder, sort the results so the folders group together, select every file, and drag the lot to the destination. For very large or messy folder trees, one Terminal command does the same job and refuses to overwrite any file that shares a name with another.

The Finder search method

  1. Open the parent folder, the one that holds all the subfolders, in Finder.
  2. Press Command-F. A search bar appears. Beside “Search:”, click the name of the current folder rather than This Mac, so the search stays inside it.
  3. The search starts with a rule that reads Kind is Any, which matches everything inside the folder. If you only want one kind of file, change Any to Image, PDF, or whatever you are after.
  4. Switch to list view with Command-2 and click the Kind column heading. If there is no Kind column, right-click any column heading and tick Kind. Folders now group together.
  5. Click the first file, then Shift-click the last, skipping the folder rows. Check the count in the status bar at the bottom (View > Show Status Bar if it is hidden).
  6. Drag the selection onto the destination folder: one in the sidebar, in another window, or on the desktop.

On the same drive, the drag moves the files. Hold Option as you drop if you want copies instead and would like the subfolders left as they were.

A few things to watch for:

  • Name clashes. Two files called IMG_0001.jpg in different subfolders cannot sit in one folder. Finder asks what to do when it reaches the second; Keep Both renames it. When Finder says an item with the same name already exists explains each choice.
  • Missing files. Finder search relies on Spotlight, so it leaves out hidden files and anything in a location excluded from Spotlight in System Settings. On an external drive that Spotlight has not indexed, the results can be incomplete. If the count looks short, use the Terminal method.
  • The empty shells. The subfolders stay behind, empty. Open a couple to confirm, then drag them to the Trash.

For a folder with only a handful of subfolders, you can skip searching. In list view, Option-click the arrow beside each subfolder to expand it, then Command-click the files you want across all of them and drag them out together.

The Terminal method

When there are thousands of files, or you want a guarantee that nothing gets overwritten, Terminal is faster and more predictable.

  1. Open Terminal from Applications > Utilities.
  2. Type cd and a space, drag the parent folder from Finder into the Terminal window, and press Return. You are now working inside that folder.

Preview what will move first. This command lists every file at least one folder down, without touching anything:

find . -mindepth 2 -type f -not -name '.*'

If the list looks right, run the move:

find . -mindepth 2 -type f -not -name '.*' -exec mv -n {} . \;

Here is what each part does. -mindepth 2 skips files that are already in the parent folder. -type f means files only, not folders. -not -name '.*' leaves out hidden files such as the .DS_Store files Finder keeps in every folder. mv -n moves each file into the current folder, and the -n means never overwrite: if a file with that name is already there, the second one stays put.

Run the preview command again afterward. Anything it still lists was left behind because of a name clash, and you can rename and move those few by hand.

To send the files to a different folder instead of the parent, replace the lone dot just before the backslash with that folder’s path. Dragging the folder into Terminal at that point types the path for you. Keep in mind that Command-Z in Finder cannot undo a move made in Terminal, which is one more reason to run the preview first.

Picking only some of the files

Often you do not want everything. Perhaps you want the finished versions and not the drafts, or a few of the best photos from each trip folder. Finder search can narrow things with rules such as a name that contains “final” or a date range, but it cannot know which photos you consider the best.

For hand-picked choices spread across many subfolders, Ledge gives you somewhere to keep what you have chosen. Open the first subfolder, drag the files you want up to the notch at the top of the screen, and let go; they land on a shelf that drops from the notch and stays there. Move on to the next subfolder and do the same. There is no selection to lose between folders, and you can take as long as you like. When you are done, open the destination folder, open the shelf with Option-Space or a click on the notch, and drag everything down onto it. Dropped on a Finder folder, the files themselves move there, which is exactly what flattening needs.

How to gather files from different folders in one spot covers this gathering habit in more detail.

Before you flatten: what you lose

Folder names often carry information: an event, a date, a client, a project. Once the files are loose in one folder, that context is gone. If it matters, put it in the file names first. Open a subfolder, select its files, right-click and choose Rename, then use Add Text to put the folder’s name before each file name. Do that for each subfolder before moving anything.

Also check how you would get back. A Finder move can usually be reversed with Command-Z straight away. How to undo a file move you did by dragging covers what to do when that window has passed.

Questions

Will moving the files change their dates?

Moving within the same drive keeps each file’s created and modified dates. The Date Added column in Finder updates, because it records when a file arrived in its current folder.

Why does my Finder search show fewer files than there are?

Spotlight skips hidden files and anything in a location excluded from its search, and a drive that has not finished indexing gives partial results. The Terminal method does not depend on Spotlight.

Can I do this on an external drive?

Yes. Both methods work on external drives. A Finder drag within the same external drive moves the files, just as it does on the internal one.