代码之家  ›  专栏  ›  技术社区  ›  Corey Floyd

通过使用NSMetadataQuery[closed]构造NSPredicate查找具有聚光灯的不可见文件夹

  •  1
  • Corey Floyd  · 技术社区  · 16 年前

    我正在构造一个NSmetaDataQuery来查找不可见的文件夹(如“.myInvisibleFolder”)。

    不幸的是,spotlight似乎无法定位以“.”开头的文件夹,即使在谓词中特别包含了这些文件夹。

    什么有效,什么无效

    搜索内容工作(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]; 
    
    }   
    
    1 回复  |  直到 16 年前
        1
  •  2
  •   Rob Keniger    16 年前

    如果我将第一个谓词更改为:

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

    你的不可见文件夹真的叫做“.MyInvisibleFolder”(注意你的不可见拼写错误)?