NSString*cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES)objectAtIndex:0];
[selffolderSizeAtPath:cachPath]afterPoint:2]];
///计算缓存文件的大小的M
- (longlong) fileSizeAtPath:(NSString*) filePath{
NSFileManager* manager = [NSFileManagerdefaultManager];
if([managerfileExistsAtPath:filePath]){
return[[managerattributesOfItemAtPath:filePatherror:nil]fileSize];
}
return0;
}
- (float) folderSizeAtPath:(NSString*) folderPath{
NSFileManager* manager = [NSFileManagerdefaultManager];
if(![managerfileExistsAtPath:folderPath])return0;
NSEnumerator*childFilesEnumerator = [[managersubpathsAtPath:folderPath]objectEnumerator];//从前向后枚举器//////
NSString* fileName;
longlongfolderSize =0;
while((fileName = [childFilesEnumeratornextObject]) !=nil){
NSLog(@"fileName ==== %@",fileName);
NSString* fileAbsolutePath = [folderPathstringByAppendingPathComponent:fileName];
NSLog(@"fileAbsolutePath ==== %@",fileAbsolutePath);
folderSize += [selffileSizeAtPath:fileAbsolutePath];
}
NSLog(@"folderSize ==== %lld",folderSize);
returnfolderSize/(1024.0*1024.0);
}
网友评论