【发布时间】:2009-10-17 20:23:09
【问题描述】:
我注意到“沼泽标准”Objective-C 文件夹检测代码存在错误。我正在扫描具有给定路径的文件和文件夹,并计算存在多少文件和存在多少文件夹。
奇怪的是,我返回的文件夹数量比实际存在的多一个!
使用调试单步执行例程并观察每个文件/文件夹名称,因为例程确定对象是文件还是文件夹,这表明其中一个文件通过了作为文件夹的测试!?!?! ?
被错误检测到的文件是“带附件的 RTF (RTFD)”文件类型。我还没有检查其他文件夹,看看是否有更多的文件类型可能会错误地报告自己。
除了这个文件之外,我的程序中的其他一切都正常工作。
有没有人知道我可能做错了什么?或者它是 Objective-C 中的一个已知错误?
这是我正在使用的部分代码:
BOOL isDir;
NSString *file;
NSString *docsDir = [self path];
NSFileManager *manager = [NSFileManager defaultManager];
NSDirectoryEnumerator *dirEnum = [manager enumeratorAtPath: docsDir];
NSDictionary *fattrs;
//(only showing important declarations above)
while (file = [dirEnum nextObject]) {
//If user clicked the Abort Button, get out of the loop
if (abortFlag)
break;
if ([excludeSubdirectories state] == NSOnState) {
[dirEnum skipDescendents];
}
if ([manager fileExistsAtPath:[docsDir stringByAppendingPathComponent:file]
isDirectory:&isDir] && isDir) {
++dirCount;
if ([excludeSubdirectories state] == NSOnState) {
continue;
}
}
}
//... Do a bunch of other stuff, etc., etc. ...
【问题讨论】:
标签: objective-c directory