根据路径获取文件大小

-(NSInteger)getSizeOfFilePath:(NSString *)filePath{
    /** 定义记录大小 */
    NSInteger totalSize = 0;
    /** 创建一个文件管理对象 */
    NSFileManager * manager = [NSFileManager defaultManager];
    /**获取文件下的所有路径包括子路径 */
    NSArray * subPaths = [manager subpathsAtPath:filePath];
    /** 遍历获取文件名称 */
    for (NSString * fileName in subPaths) {
        /** 拼接获取完整路径 */
        NSString * subPath = [filePath stringByAppendingPathComponent:fileName];
        /** 判断是否是隐藏文件 */
        if ([fileName hasPrefix:@".DS"]) {
            continue;
        }
        /** 判断是否是文件夹 */
        BOOL isDirectory;
        [manager fileExistsAtPath:subPath isDirectory:&isDirectory];
        if (isDirectory) {
            continue;
        }
        /** 获取文件属性 */
        NSDictionary *dict = [manager attributesOfItemAtPath:subPath error:nil];
        /** 累加 */
        totalSize += [dict fileSize];
        
    }
    /** 返回 */
    return totalSize;
}
原文地址:https://www.cnblogs.com/pengyunjing/p/5998789.html