首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过使用NSMetadataQuery构建NSPredicate,使用spotlight查找不可见文件夹

通过使用NSMetadataQuery构建NSPredicate,使用spotlight查找不可见文件夹
EN

Stack Overflow用户
提问于 2009-09-17 21:37:26
回答 1查看 797关注 0票数 1

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

不幸的是,spotlight似乎不能定位以".“开头的文件夹,即使特别包含在谓词中也是如此。

什么管用什么不管用

搜索任何不可访问的文件名都是有效的。

搜索内容工作(kMDItemTextContent)。

没有以".“开头的文件。从未被发现过。始终返回0结果。

作为测试,在Finder中搜索不可见的内容是可行的。

我做错了什么?有没有其他方法可以找到不可见的文件夹?

代码:

代码语言:javascript
复制
- (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]; 

}   
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2009-09-17 23:35:41

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

代码语言:javascript
复制
[NSPredicate predicateWithFormat:@" (kMDItemFSName == '.DS_Store')"];

你的不可见文件夹真的叫".myInvisableFolder“吗(注意你对不可见的拼写错误)?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1441466

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档