Flatten directories with Spotlight
Though I have a love/hate relationship with Spotlight, there are times when its features come in handy. Consider this example. A client has sent you a CD with a few hundred images to use in a new Web site design, and you’ve copied the CD’s contents to a folder on your hard drive. When you open the folder in the Finder, you see a structure like this:
- Nature Images
- Sunset beach.jpg
- Lush pond.jpg
- Industrial Images
- Deserted factory.jpg
- Concrete bridge.jpg
This structure goes on and one, with a few images in each subfolder. Unfortunately, your business organizes images by client and project: Client XYZ -> Project ABC -> Images. So your task is to take all of the client-provided images, buried in multiple subdirectories, and move them all into the proper project-related Images folder. What makes this a bit of a chore, of course, is the fact that the images are spread throughout numerous folders.
There are many good ways to accomplish this task, but I’ll give you one you may not have considered: use Spotlight. When you run a Spotlight search in the Finder, the results are presented in one window, regardless of where the located files actually reside. We can use this behavior to make it really simple to group our widely-scattered files.
Navigate to the folder where the files you’d like to group are located, then press Command-F to activate the Finder’s search mode. When the search options appear, notice that it’s already defaulted to searching within the folder you selected. You’ll also see the two default search criteria (Kind — Any and Last Opened — Any Date).
At this point, there are two ways to proceed, depending on whether you’re trying to group all files, or just some that share a given characteristic, such as part of their filename.
If you want to grab every single file within a folder structure, it’s quite simple. First remove the Last Opened — Any Date criteria by clicking the minus sign next to its entry in the Finder window. Then click the Kind drop-down for the remaining criteria, and change it to Size. Leave the new Greater than drop-down exactly as it is, and then put 0 into the text field:
As soon as you type the 0 , Spotlight will start searching and return essentially every file (since you told it to find any file with a size greater than zero) within the folder structure—including all subfolders. But the way the results are presented doesn't make it look particularly easy to select all of your files. We'll get to that bit in just a minute.
In the example above, all we really want are the image files, and it seems they’ve all been named to end with .jpg . As before, we’ll start by removing the Last Opened — Any Date criteria. Click the Kind drop-down for the first criteria, and change it to Name. Then set the next drop-down to Ends With, and type .jpg in the text input box, like this:
Obviously, you can change and add criteria as necessary to match what you want to find in the folder structure. Spotlight starts searching as soon as you give it a valid criteria to search with, and soon, all of the matches will appear in the window.
So what now?
Regardless of which search you ran, you can press Command-A to select everything in the Finder’s search results window, and then just drag and drop it to its final destination. This works great if you searched only for files that matched a certain criteria.
If you searched for all files, though, then the Command-A method will also copy all the parent folders and any other files you might not want to copy. So press Command-2 instead (View -> As List) to switch to list view mode. Once in list view, click the Kind column heading to help separate the files and folders, then select and copy the files you wish to copy.
There are obviously endless variations of this technique; the thing to keep in mind is just the general concept: Spotlight searches in the Finder will consolidate many separate folders into one “ultra folder” for display purposes. This makes it super easy to then do things with these consolidated files that might otherwise be somewhat time consuming.