首页 > 代码库 > ios 得到文件夹大小 进率是1000
ios 得到文件夹大小 进率是1000
- (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;
{
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];
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。