NSFileManager 获取某个路径下的文件大小
作者:
上北以北 | 来源:发表于
2022-04-26 20:11 被阅读0次//获取某个路径下所有文件大小
- (long long)fileSizeForPath:(NSString*)path {
long long size = 0;
if (!path.length) {
return size;
}
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray<NSString *>* subPaths = [fileManager contentsOfDirectoryAtPath:path error:nil];
if (subPaths.count) {
for (NSString *childPath in subPaths) {
NSString *c_path = [path stringByAppendingPathComponent:childPath];
if ([fileManager fileExistsAtPath:c_path]) {
size += [self fileSizeForPath:c_path];
}
}
} else {
NSDictionary *fileAttributeDic = [fileManager attributesOfItemAtPath:path error:nil];
size = fileAttributeDic.fileSize;
}
return size;
}
本文标题:NSFileManager 获取某个路径下的文件大小
本文链接:https://www.haomeiwen.com/subject/jcyhyrtx.html
网友评论