zoukankan      html  css  js  c++  java
  • 计算沙盒中一个目录的大小

    +(NSString*)getCacheSize
    {
         
        NSDate* begin = [NSDate date];
     
     
        NSFileManager* fm = [NSFileManager defaultManager];
        __block NSError* error = nil;
         
        __block NSUInteger fileSize = 0;
         
         
        //获取Books的缓存
        dispatch_sync(queue, ^{
            NSArray* subFiles = [fm subpathsAtPath:BOOKHEADERPath([LoginPlugin share].userID)];
            NSLog(@"subpath = %@",subFiles);
            for (NSString* fileName in subFiles) {
                if ([fileName hasSuffix:@"png"]||[fileName hasSuffix:@"jpg"]) {
                    NSDictionary* dic = [fm attributesOfItemAtPath:BOOKPATH([LoginPlugin share].userID,fileName) error:&error];
                    NSUInteger size = (error ? 0:[dic fileSize]);
                    fileSize += size;
                }
            }
        });
         
         
        NSString* cacheString = [NSString stringWithFormat:@"%.1fM",fileSize/(1024.0*1024)];
        NSTimeInterval time = [begin timeIntervalSinceNow];
        NSLog(@"便利文件耗费时间:%lf",time/60.0);
        return cacheString;
    }
  • 相关阅读:
    uva129
    uva167
    【Linux】touch命令
    【Linux】od命令
    【Linux】tail命令
    【Linux】head命令
    【Linux】less命令
    【Linux】more命令
    【Linux】nl命令
    【Linux】cat命令
  • 原文地址:https://www.cnblogs.com/weiboyuan/p/8961963.html
Copyright © 2011-2022 走看看