为什么 NSDirectoryEnumerator 在这里获取隐藏文件?
我需要避免此枚举中的隐藏文件,但仍在添加 .DS_Store 文件。
我放入 NSLog 进行检查,并在那里得到输出。
可能有一些明显的东西,但我看不到。
NSDirectoryEnumerator *dirEnumerator;
NSFileManager *fileManager = [[NSFileManager alloc] init];
dirEnumerator = [fileManager enumeratorAtURL:item
includingPropertiesForKeys:[NSArray array]
options:NSDirectoryEnumerationSkipsPackageDescendants || NSDirectoryEnumerationSkipsHiddenFiles
errorHandler:nil];
for (NSURL *urlItem in dirEnumerator) {
// is item hidden ?
NSNumber *isHidden = nil;
if ([urlItem getResourceValue:&isHidden forKey:NSURLIsHiddenKey error:nil]) {
if ([isHidden isEqual:[NSNumber numberWithInt:1]]) {
NSLog(@"isHidden is 1");
continue;
}
}
i need to avoid hidden files in this enumeration, but .DS_Store files are still being added.
i put in the NSLog to check, and i am getting output there.
there's probably something obvious, but i can't see it.
NSDirectoryEnumerator *dirEnumerator;
NSFileManager *fileManager = [[NSFileManager alloc] init];
dirEnumerator = [fileManager enumeratorAtURL:item
includingPropertiesForKeys:[NSArray array]
options:NSDirectoryEnumerationSkipsPackageDescendants || NSDirectoryEnumerationSkipsHiddenFiles
errorHandler:nil];
for (NSURL *urlItem in dirEnumerator) {
// is item hidden ?
NSNumber *isHidden = nil;
if ([urlItem getResourceValue:&isHidden forKey:NSURLIsHiddenKey error:nil]) {
if ([isHidden isEqual:[NSNumber numberWithInt:1]]) {
NSLog(@"isHidden is 1");
continue;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,真正的问题是您使用了错误的运算符来指定掩码:
执行布尔
OR
,为您提供1
,这不是一个有用的选项掩码。您需要使用单管道:按位
OR
。旧答案:
您需要实际请求要查看的属性:
来自
-[NSURL getResourceValue:forKey:error:]
文档:Actually, the real problem is that you're using the wrong operator to specify the mask:
does Boolean
OR
, giving you1
, which isn't a useful options mask. You need to use the single pipe:which is bitwise
OR
.OLD ANSWER:
You need to actually request the properties that you're going to look at:
from the
-[NSURL getResourceValue:forKey:error:]
doc: