2009-09-17 21 views
1

我构建NSmetaDataQuery找到隐形的文件夹(如“.myInvisibleFolder”)查找与聚光灯看不见的文件夹。通过构建一个NSPredicate与NSMetadataQuery

不幸的是,镁光灯似乎并没有被定位文件夹开头“”,即使具体包括在谓语。

什么工作和不工作

搜索任何非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

默认情况下Spotlight排除不可见文件夹。这实际上是积极用于防止文档包在完全写入磁盘之前建立索引:[Spotlight和隐形文件/文件夹](https://developer.apple.com/library/mac/#documentation/Carbon/Conceptual/MetadataIntro /Concepts/DocumentBundles.html) – Jay 2012-09-30 07:44:19

回答

2

您的代码完全适用于我,如果我改变第一谓词:

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

是您真的叫“.myInvisableFolder”看不见的文件夹(注意您的无形拼写错误)?

+0

好吧,不知道发生了什么,但现在它正在工作。感谢您为我测试它! – 2009-09-18 14:22:37

相关问题