码迷,mamicode.com
首页 > 其他好文 > 详细

文件大小计算

时间:2016-07-10 12:26:21      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic,assign) CGFloat size;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSString * path = @"/Users/tc/Desktop/图片text";
    NSLog(@"%g",[self FileSize:path]);
}
/**
 *  @param path 文件的绝对路径
 */
- (CGFloat)FileSize:(NSString *)path{
    
    NSFileManager * manager = [NSFileManager defaultManager];
    
    NSArray * arr = [manager contentsOfDirectoryAtPath:path error:nil];
    
    BOOL isDir;
    for (NSString * fileName in arr) {
        NSString * filePath = [path stringByAppendingPathComponent:fileName];
        if (!([manager fileExistsAtPath:filePath isDirectory:&isDir] && isDir)) {
            NSDictionary * dic = [manager attributesOfItemAtPath:filePath error:nil];
            _size += dic.fileSize;
        }else{
            [self FileSize:filePath];
        }
    }
    return _size;
}
@end

 

文件大小计算

标签:

原文地址:http://www.cnblogs.com/tcbky/p/5657392.html

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