ios 得到目录大小 进率是1000

- (CGFloat)folderSizeAtPath:(NSString *) folderPath
{
    NSFileManager * manager = [NSFileManager defaultManager];
    
    if (![manager fileExistsAtPath:folderPath])
    {
      return 0;
    }
    
    NSEnumerator * childFilesEnumerator = [[manager subpathsAtPath:folderPath] objectEnumerator];
    NSString * fileName;

    long long folderSize = 0;
    
    while ((fileName = [childFilesEnumerator nextObject]) != nil)
    {
        
        NSString * fileAbsolutePath = [folderPath stringByAppendingPathComponent:fileName];
        
        float singleFileSize = 0.0;
        if ([manager fileExistsAtPath:fileAbsolutePath])
        {
            singleFileSize = [[manager attributesOfItemAtPath:fileAbsolutePath error:nil] fileSize];
            NSLog(@"singleFileSize %f",singleFileSize);
        }
        folderSize += singleFileSize;
    
    }
    NSLog(@"count file size %f",folderSize/1000.0);
    return folderSize/1000.0;
    

}


调用 :


    NSString * filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",@"TencentOpenApi_IOS_Bundle.bundle"]];
    
    [self folderSizeAtPath:filePath];

posted @ 2014-05-29 14:48  mfrbuaa  阅读(149)  评论(0编辑  收藏  举报