NSDirectoryEnumerator 枚举器
nextObject返回nil值时,循环结束。这也是不能在数组中存储nil值的另一个原因:没办法判断nil是存储在数组中的数值还是代表循环结束的标志。
+ (long long)getFileSize{
NSFileManager* fileManager=[NSFileManager defaultManager];
NSDirectoryEnumerator * enumerator = [fileManager enumeratorAtPath:NSHomeDirectory()];
long long totalSize = 0;
NSString * aPath = @"";
while (aPath = [enumerator nextObject]) {
NSString * realPath = [NSHomeDirectory() stringByAppendingPathComponent:aPath];
NSDictionary * dic = [fileManager attributesOfItemAtPath:realPath error:nil];
totalSize += [dic[@"NSFileSize"] longLongValue];
}
NSLog(@"------- 总大小为: %.2f",totalSize/1000.0/1000.0);
totalSize = totalSize/1000.0/1000.0;
return totalSize;
}