标签:
#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