1

非表示のフォルダー (「.myInvisibleFolder」など) を見つけるために NSmetaDataQuery を作成しています。

残念ながら、述語に明確に含まれている場合でも、スポットライトは「.」で始まるフォルダーを見つけていないようです。

機能するものと機能しないもの

見えないファイル名の検索は機能します。

コンテンツの検索が機能します (kMDItemTextContent)。

「.」で始まるファイルはありません が見つかったことがあります。常に 0 の結果を返します。

テストとして、Finder 内の非表示コンテンツの検索は機能します。

私は何を間違っていますか?非表示のフォルダを見つける別の方法はありますか?

コード:

- (void)searchForMyInvisableFolders{
    self.query = [[[NSMetadataQuery alloc] init] autorelease];

    // To watch results send by the query, add an observer to the NSNotificationCenter
    NSNotificationCenter *nf = [NSNotificationCenter defaultCenter];
    [nf addObserver:self selector:@selector(queryNote:) name:nil object:self.query];

    // Sort results by file name
    [self.query setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:(id)kMDItemFSName ascending:YES] autorelease]]];

    [self.query setDelegate:self];

    //Create a predicate to search for file name
    NSPredicate* predicate = [NSPredicate predicateWithFormat:@" (kMDItemFSName == '.myInvisibleFolder')"];

    //Create a predicate to search for invisible files
    NSPredicate* invisablePredicate = [NSPredicate predicateWithFormat:@"kMDItemFSInvisible == YES"];

    //Compound predicate
    NSPredicate* compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:[NSArray arrayWithObjects:predicate, invisiblePredicate, nil]]; 

    // Set it to the query.
    [self.query setPredicate:compoundPredicate];           

    // Start it.
    [self.query startQuery]; 

}   
4

1 に答える 1

2

最初の述語を次のように変更すると、コードは完全に機能します。

[NSPredicate predicateWithFormat:@" (kMDItemFSName == '.DS_Store')"];

あなたの非表示フォルダーは本当に「.myInvisableFolder」と呼ばれていますか (非表示のスペルミスに注意してください)。

于 2009-09-17T23:35:40.760 に答える