- (unsigned long long)enumeratorWithPath:(NSString *)filePath{
//注释 ios的文件大小以1000为单位,不是以1024作为单位.
unsigned long long folderSize = 0 ;
NSFileManager * fileManager = [NSFileManager defaultManager];
//文件是否存在
BOOL isExist;
//是否文件夹
BOOL isFolder;
isExist = [fileManager fileExistsAtPath:filePath isDirectory:&isFolder ];
if (!isExist) {
return 0;
}
if (isFolder) {
//是文件夹
NSEnumerator * childFileEnumerator = [[fileManager subpathsAtPath:filePath] objectEnumerator];
NSString * fileName;
while ((fileName = [childFileEnumerator nextObject]) != nil) {
NSString * fileAbsolutePath = [filePath stringByAppendingPathComponent:fileName];
folderSize += [[fileManager attributesOfItemAtPath:fileAbsolutePath error:nil] fileSize];
NSLog(@"%@",fileAbsolutePath);
}
}else{
//不是文件夹
folderSize = [[fileManager attributesOfItemAtPath:filePath error:nil] fileSize];
}
NSLog(@"%.2llu",folderSize);
return folderSize;
}