zoukankan      html  css  js  c++  java
  • 计算文件大小的分类

    @implementation NSString (fileSize)
    
    - (unsigned long long)fileSize
    {
        // 总大小
        unsigned long long size = 0;
    
        // 文件管理者
        NSFileManager *mgr = [NSFileManager defaultManager];
    
        // 文件属性
        NSDictionary *attrs = [mgr attributesOfItemAtPath:self error:nil];
    
        if ([attrs.fileType isEqualToString:NSFileTypeDirectory]) { // 文件夹
            // 获得文件夹的大小  == 获得文件夹中所有文件的总大小
            NSDirectoryEnumerator *enumerator = [mgr enumeratorAtPath:self];
            for (NSString *subpath in enumerator) {
                // 全路径
                NSString *fullSubpath = [self stringByAppendingPathComponent:subpath];
                // 累加文件大小
                if ([[mgr attributesOfItemAtPath:fullSubpath error:nil].fileType isEqualToString:NSFileTypeDirectory]) { //如果遍历到的是文件夹,那么继续遍历,只增加文件(而不是文件夹)的大小
                    continue;
                }
                size += [mgr attributesOfItemAtPath:fullSubpath error:nil].fileSize;
                NSLog(@"---%@",fullSubpath);
            }
        } else { // 文件
            size = attrs.fileSize;
           
    
        }
    
        return size;
    }
    
    @end
  • 相关阅读:
    移动网络优化
    移动网络架构与数据传输
    移动网络简介与RRC
    CSS之外边距折叠
    网络协议之TLS
    Smarty 模板引擎简介
    FormData介绍
    相对路径与绝对路径
    OAuth2.0
    Redis学习手册(List数据类型)
  • 原文地址:https://www.cnblogs.com/yintingting/p/5467755.html
Copyright © 2011-2022 走看看