Mac search- any means of "folders that contain"? Also: template searches?

That’s it: with 3rd party or within Spotlight, is there any means of searching for, as an example, “folders that contain mp3s but do not contain PDFs or MP4s”.

I am very familiar with the way to structure searches that DO this but NOT that (If anyone reading this does not know how to do this: when you go to click on the + sign that allows additional criteria for a search, hold down the option key, it will turn to ellipses and give you more advanced options…)

The tricky bit is specifying returned results (folders) based on the characteristics of the files the folders contain.

(Not to be pessimistic, but I’ve been a Mac geek for 30 years, and such a digital hoarder that super-specific searching has always been my thing, and I’v never figured this one out. So I’m anticipating crickets. Hope not, tho…)

Also: regarding “smart” searches. Again, because of my insane search needs and my insane digital hoarding, I find myself having to structure multi-step searches. I would love to be able to save them as templates, meaning without any key data being searched for, just the various options for inclusion and exclusion preserved. Haven’t figured out how to make that happen, so I’m stuck with creating a search that has the data plugged in, and I just have to change it, but that can be surprisingly annoying. So if anyone has the secret…assuming one exists.

And finally: I have Houdahspot, which is pretty bitchen for refining searches and getting more data, so if someone knows how to do what I want with that…

Pop your file list into Excel and use functions/filters/conditional formatting to find what you’re looking for. Make macros as needed.

That assumes you know how to use Excel.

Given OS-X is a Unix system, you can quite reasonably use the Unix tools to do this.

The find command gets you a very long way towards what you want. Assuming the file name extensions are used.

You do of course need to be happy using the command line. But you can achieve an enormous amount with not a lot of effort. Add the commands like uniq and awk[sup]*[/sup], and you can perform wonders.

  • OK, awk is not exactly for the faint hearted.

Also looks like this might be the sort of thing you are looking for:

Actually “find” isn’t particularly well suited to detecting whether a directory contains certain types of files, but here’s one rather verbose way to do what the OP wants:

find . -type d | while read d; do if [ “echo $d/*.mp3” != “$d/.mp3" -a “echo $d/*.mp4” = "$d/.mp4” -a “echo $d/*.pdf” = “$d/*.pdf” ]; then echo $d; fi; done

–Mark

I’m not an Excel wizard, but I can make my way around a few things beyond the the basics. How I would use Excel to find folders that contain X but not Y stumps me completely… and I think the problem is the popping of my file list into Excel… there is no file list…at least not initially… are you saying there is a kind of starting search I could do that could then be further refined within an Excel spreadsheet? I would love to know how that works, just for the education of it because I can’t begin to guess and it fascinates me to learn new unexpected stuff. IN a practical sense that wouldn’t meet my need because it’s too much just for file searching.

Why not use find to search for the “mp3”, “mp4”, and “pdf” extensions directly, and then pipe the results to “dirname” to get the directory?


find . -name "*.mp3" -exec dirname {} +

This command only does the first part of what the OP asks. To eliminate the directories that also contain PDFs or MP4s, save the results of analogous commands to text files and then compute the set difference:



find . -name "*.mp3" -exec dirname {} + > dirs-with-mp3s
find . -name "*.mp4" -exec dirname {} + > dirs-with-mp4s
find . -name "*.pdf" -exec dirname {} + > dirs-with-pdfs
cat dirs-with-mp3s dirs-with-mp4s dirs-with-mp4s | sort | uniq -u > first-elimination
cat first-elimination dirs-with-pdfs dirs-with-pdfs | sort | uniq -u


In order to use the set difference, the text files in question should actually be sets, so we first have to eliminate duplicates from each find command. While we’re at it, make the find command case-insensitive.



find . -iname "*.mp3" -exec dirname {} + | uniq > dirs-with-mp3s
find . -iname "*.mp4" -exec dirname {} + | uniq > dirs-with-mp4s
find . -iname "*.pdf" -exec dirname {} + | uniq > dirs-with-pdfs
cat dirs-with-mp3s dirs-with-mp4s dirs-with-mp4s | sort | uniq -u > first-elimination
cat first-elimination dirs-with-pdfs dirs-with-pdfs | sort | uniq -u


Disclaimer: I haven’t yet tested the script on an OS X Terminal, but in GNU/Linux it works as advertised.