码迷,mamicode.com
首页 > 移动开发 > 详细

ios 得到文件夹大小 进率是1000

时间:2014-04-29 13:36:20      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:os   文件   io   for   re   c   

- (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];

ios 得到文件夹大小 进率是1000,码迷,mamicode.com

ios 得到文件夹大小 进率是1000

标签:os   文件   io   for   re   c   

原文地址:http://blog.csdn.net/beijingak/article/details/24703553

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!