No results in Spotlight searches against kMDItemPath

I am trying to create a Spotlight query that searches for a string in a file path (I would like it to match either the file name or the name of any of the folders).

NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat: @"kMDItemPath like[wcd] $SEARCH";
[query setPredicate: 
    [predicateTemplate predicateWithSubstitutionVariables:
        [NSDictionary dictionaryWithObject:searchingFor forKey:@"SEARCH"]
    ]
];
[query startQuery];

This always returns 0 results, even if the following:

NSPredicate *predicateTemplate = [NSPredicate predicateWithFormat: @"kMDItemDisplayName in[wcd] $SEARCH";

returns 1 or more results. I am testing this on MacOS X 10.5.8.

+3
source share
1 answer

Enter documentation:

kMDItemPath

End the file path. This attribute value can be restored, but cannot be used in a query or for sorting search results.

Link

, kMDItemPath MDItem NSMetadataItem . MDQuery NSMetadataQuery , .

+7

Source: https://habr.com/ru/post/1716222/


All Articles