zoukankan      html  css  js  c++  java
  • ios 计算缓存大小

    - (void)getSize2

    {

        // 图片缓存

        NSUInteger size = [SDImageCache sharedImageCache].getSize;

        //  NSLog(@"%zd %@", size, NSTemporaryDirectory());

        

        NSFileManager *manager = [NSFileManager defaultManager];

        

        // 文件夹

        NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

        NSString *cachePath = [caches stringByAppendingPathComponent:@"default/com.hackemist.SDWebImageCache.default"];

        

        // 获得文件夹内部的所有内容

        //    NSArray *contents = [manager contentsOfDirectoryAtPath:cachePath error:nil];

        NSArray *subpaths = [manager subpathsAtPath:cachePath];

        NSLog(@"%@", subpaths);

    }

     

    - (void)getSize

    {

        NSFileManager *manager = [NSFileManager defaultManager];

        

        NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];

        NSString *cachePath = [caches stringByAppendingPathComponent:@"default/com.hackemist.SDWebImageCache.default"];

        

        NSDirectoryEnumerator *fileEnumerator = [manager enumeratorAtPath:cachePath];

        NSInteger totalSize = 0;

        for (NSString *fileName in fileEnumerator) {

            NSString *filepath = [cachePath stringByAppendingPathComponent:fileName];

            

    //        BOOL dir = NO;

    // 判断文件的类型:文件文件夹

    //        [manager fileExistsAtPath:filepath isDirectory:&dir];

    //        if (dir) continue;

            NSDictionary *attrs = [manager attributesOfItemAtPath:filepath error:nil];

            if ([attrs[NSFileType] isEqualToString:NSFileTypeDirectory]) continue;

            

            totalSize += [attrs[NSFileSize] integerValue];

        }

      NSLog(@"%zd", totalSize);

    }

     

  • 相关阅读:
    pyftpdlib 搭建FTP服务器
    numpy 解一道简单数学题
    python 实现词云
    个人的毕业长足---- 暴走北京
    Tensorflow of GPU, hello fish by version 0.8.
    图像识别
    用一个Inception v3 架构模型实现简单的迁移学习(译:../tensorflow/tensorflow/examples/image_retraining/retrain.py)
    19.液晶屏的原理
    18.DMA-6410
    17.DMA-2440
  • 原文地址:https://www.cnblogs.com/soulDn/p/5779135.html
Copyright © 2011-2022 走看看