2009-09-17 5 views
1

보이지 않는 폴더 (예 : ".myInvisibleFolder")를 찾으려면 NSmetaDataQuery를 생성해야합니다.NSMetadataQuery를 사용하여 NSPredicate를 구성하여 스포트라이트가있는 보이지 않는 폴더 찾기

불행히도, spotlight는 특별히 "."로 시작하는 폴더를 찾지 못하는 것 같습니다. 작동 및 비 invisable 파일 이름의 작품을 검색

작동하지 않습니다 무엇

.

콘텐츠 검색 중 (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]; 

} 
+0

기본적으로 스포트라이트는 보이지 않는 폴더를 제외합니다. 그것은 실제로 문서 번들이 디스크에 완전히 기록되기 전에 색인 생성을 방지하기 위해 실제로 사용됩니다 : [스포트라이트 및 보이지 않는 파일/폴더] (https://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/MetadataIntro /Concepts/DocumentBundles.html) – Jay

답변

2

귀하의 코드는 I가 첫 번째 조건을 변경하면 나를 위해 완벽하게 작동합니다 :

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

정말 ".myInvisableFolder"라는 보이지 않는 폴더 (눈에 보이지 않는 당신의 맞춤법에주의)?

+0

무슨 일이 일어나고 있는지 확실하지 않지만 지금은 효과가 있습니다. 나를 테스트 해 주셔서 감사합니다! –