问题描述
我正在使用NSDirectoryEnumerator枚举文件夹,但是问题是在枚举完成之前cpu百分比增加了50%以上。有什么方法可以解决这个问题?
-(void)enumerateFolder:(Nsstring *)folder{
NSURL *directoryURL = [NSURL fileURLWithPath:folder];
NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey];
NSInteger fileCount = 0;
NSInteger folderCount = 0;
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]
enumeratorAtURL:directoryURL
includingPropertiesForKeys:keys
options:0
errorHandler:^BOOL(NSURL *url,NSError *error) {
// Handle the error.
// Return YES if the enumeration should continue after the error.
return YES;
}];
for (NSURL *url in enumerator)
{
NSError *error;
NSNumber *isDirectory = nil;
if (! [url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error]) {
// handle error
}
else if (! [isDirectory boolValue]) {
// No error and it’s not a directory; do something with the file
fileCount++;
}else if([isDirectory boolValue]){
folderCount++;
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)