2008 11 21Finding files with a specific extension
I had trouble trouble with building the query to find files by extension, so here goes :
id query = [[NSMetadataQuery alloc] init]; // Search for .jscocoa files id predicate = [NSPredicate predicateWithFormat:@"(kMDItemFSName like[c] %@)", @"*.jscocoa"]; [query setPredicate:predicate]; // Restrict search to user's home directory [query setSearchScopes:[NSArray arrayWithObject:NSHomeDirectory()]]; // And go ! [query startQuery];
When you do a Spotlight search and save it as a smart folder, Finder saves it as a property list. You can then drag it to your favorite text editor and copy the query, and use it with mdfind
in Terminal. BUT NSPredicate
's syntax is different, you need to tweak it :
Tooting my own horn: try HoudahSpot.
"File name" "ends with" ".jscocoa"
Save as template