您的位置:首页 > 其它

nsfilemanger 怎么求沙盒目录下某一文件夹的大小

2013-03-20 13:07 239 查看
+(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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: