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

**URL:** <https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572>\
**Category:** Factual Questions\
**Created:** [March 29, 2016, 9:35pm UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572 "2016-03-29T21:35:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/stoid/32/272_2.png) [@Stoid](https://boards.straightdope.com/u/Stoid)\
**Post date:** [March 29, 2016, 9:35pm UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/1 "2016-03-29T21:35:35Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Green\_Bean](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/green_bean/32/1760_2.png) [@Green\_Bean](https://boards.straightdope.com/u/Green_Bean)\
**Post date:** [March 30, 2016, 3:09am UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/2 "2016-03-30T03:09:41Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Francis\_Vaughan](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/francis_vaughan/32/3093_2.png) [@Francis\_Vaughan](https://boards.straightdope.com/u/Francis_Vaughan)\
**Post date:** [March 30, 2016, 3:35am UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/3 "2016-03-30T03:35:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![coremelt](https://avatars.discourse-cdn.com/v4/letter/c/4491bb/32.png) [@coremelt](https://boards.straightdope.com/u/coremelt)\
**Post date:** [March 30, 2016, 4:15am UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/4 "2016-03-30T04:15:29Z")

</div>

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

> **[NeoFinder - Digital Asset Management Software](https://www.cdfinder.de/)**
>
> Discover NoFinder, the Digital Asset Management tool for macOS and iOS. Try the amazing NeoFinder today.

---

<div class="post-metadata">

**Author:** ![markn\_1](https://avatars.discourse-cdn.com/v4/letter/m/f9ae1b/32.png) [@markn\_1](https://boards.straightdope.com/u/markn_1)\
**Post date:** [March 30, 2016, 4:33am UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/5 "2016-03-30T04:33:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stoid](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/stoid/32/272_2.png) [@Stoid](https://boards.straightdope.com/u/Stoid)\
**Post date:** [March 30, 2016, 6:41am UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/6 "2016-03-30T06:41:59Z")

</div>

> [@Green\_Bean](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![biqu](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@biqu](https://boards.straightdope.com/u/biqu)\
**Post date:** [March 31, 2016, 2:32pm UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/7 "2016-03-31T14:32:06Z")

</div>

> [@markn\_1](#):
>
> 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

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?

```auto

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

```

---

<div class="post-metadata">

**Author:** ![biqu](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@biqu](https://boards.straightdope.com/u/biqu)\
**Post date:** [March 31, 2016, 5:02pm UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/8 "2016-03-31T17:02:30Z")

</div>

> [@biqu](#):
>
> ```auto
> 
> 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](http://stackoverflow.com/questions/2509533/bash-linux-set-difference-between-two-text-files):

```auto

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

```

---

<div class="post-metadata">

**Author:** ![biqu](https://avatars.discourse-cdn.com/v4/letter/b/7feea3/32.png) [@biqu](https://boards.straightdope.com/u/biqu)\
**Post date:** [March 31, 2016, 5:41pm UTC](https://boards.straightdope.com/t/mac-search-any-means-of-folders-that-contain-also-template-searches/750572/9 "2016-03-31T17:41:48Z")

</div>

> [@biqu](#):
>
> save the results of analogous commands to text files and then compute the [set difference](http://stackoverflow.com/questions/2509533/bash-linux-set-difference-between-two-text-files):

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.

```auto

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.
