2009-08-27 62 views
3

我想創建一個Spotlight查詢來搜索文件路徑中的字符串(我希望它匹配文件的名稱或任何該文件夾包含在)。Spotlight在搜索kMDItemPath中沒有結果

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

這總是返回0的結果,即使在以下之一:

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

返回1個或多個結果。我在MacOS X 10.5.8上測試這個。

回答

6

文檔答曰:

kMDItemPath

完整的文件路徑。可以檢索此屬性的此值,但不能用於查詢或排序搜索結果。

Link

這意味着屬性kMDItemPath只能與MDItem或NSMetadataItem用於檢索已經找到一個項目的路徑。您不能在您指定的查詢謂詞中使用MDQuery或NSMetadataQuery來查找文件。