+(float)fileSizeForDir:(NSString*)path//计算文件夹下文件的总大小
{
NSFileManager *fileManager = [[NSFileManager alloc] init];
float size =0;
NSArray* array = [fileManager contentsOfDirectoryAtPath:path error:nil];
for(int i = 0; i<[array count]; i++)
{
NSString *fullPath = [path stringByAppendingPathComponent:[array objectAtIndex:i]];
BOOL isDir;
if ( !([fileManager fileExistsAtPath:fullPath isDirectory:&isDir] && isDir) )
{
NSDictionary *fileAttributeDic=[fileManager attributesOfItemAtPath:fullPath error:nil];
size+= fileAttributeDic.fileSize/ 1024.0/1024.0;
}
else
{
[self fileSizeForDir:fullPath];
}
}
[fileManager release];
return size;
}
转自
http://www.cocoachina.com/ask/questions/show/94167/nsfilemanger%E6%80%8E%E4%B9%88%E6%B1%82%E6%B2%99%E7%9B%92%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9F%90%E4%B8%80%E6%96%87%E4%BB%B6%E5%A4%B9%E7%9A%84%E5%A4%A7%E5%B0%8F