Smart Folder: how to create listing of all files in a folder?

I want to create a Smart Folder which just lists all files of my ~/Music directory - i.e. just a flattened version of that folder.

How can I do this?

(I tried to type * in the search field, but that doesn't list all files.)


Solution 1:

By default, the Spotlight GUI in the Finder will not let you use wildcards or other advanced syntax. However, by using the Raw Query search criterion, you can use all the syntax available to the command-line mdfind utility:

  • Navigate to your ~/Music folder
  • Hit ⌘ F
  • Double-check the Scope Bar of the search to make sure Spotlight is just searching your Music folder
  • Hit the "+" button to add a search criterion
  • From the criteria drop-down menu, check if the Raw Query criterion is visible (it isn't by default). If not, click Other... and a criteria list will appear. Search for the Raw Query criterion, check the box to include it in the menu, and click "OK".
  • Select the newly-visible Raw Query criterion and enter the following:

    (kMDItemFSName == '*.mp3') || (kMDItemFSName == '*.ogg') || (kMDItemFSName == '*.flac')
    

The above query will search for files that have .mp3, .ogg, or .flac in their filename (as opposed to the contents of the file). This Macworld article helped me construct this particular query, but this Apple Developer page has a more comprehensive listing of the types of metadata available for raw queries.


Alternatively, you can construct the desired query visually:

Spotlight query

  • Navigate to your ~/Music folder
  • Hit ⌘ F
  • Double-check the Scope Bar of the search to make sure Spotlight is just searching your Music folder
  • Hit the "+" button to add a search criterion
  • Choose the Kind criterion and set it to Any
  • Hold down the Option/Alt key to create a conditional (thanks to Adam Franco for pointing this out) and set it to Any
  • From the criteria drop-down menu, check if the File extension criterion is visible. If not, click Other... and a criteria list will appear. Search for the File extension criterion, check the box to include it in the menu, and click "OK".
  • Add as many File extension criteria as you wish.

If you want the search to display all files below a given folder (regardless of file type), you can use the File visibility criterion:

  • Navigate to your ~/Music folder
  • Hit ⌘ F
  • Double-check the Scope Bar of the search to make sure Spotlight is just searching your Music folder
  • Hit the "+" button to add a search criterion
  • From the criteria drop-down menu, check if the File visibility criterion is visible (it isn't by default). If not, click Other... and a criteria list will appear. Search for the File invisible criterion, check the box to include it in the menu, and click "OK".
  • The File visibility option should now be in the search criterion drop-down menu. So long as this criterion is set to "Visible or Invisible", all files below the present folder will be shown (you can optionally change this to "Visible Items" you don't want dot-files in the results)

Solution 2:

It looks like just typing a . in the search field shows all files, but not folders.