IOS 缓存大小计算

作者: 小暖风 | 来源:发表于2017-08-19 14:20 被阅读9次

    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);

    }

    相关文章

      网友评论

        本文标题:IOS 缓存大小计算

        本文链接:https://www.haomeiwen.com/subject/ocytdxtx.html