• 获取文件夹大小


    - (unsignedlonglongint)folderSize:(NSString *)folderPath {
        NSArray *filesArray = [[NSFileManagerdefaultManager] subpathsOfDirectoryAtPath:folderPath error:nil];
        NSEnumerator *filesEnumerator = [filesArray objectEnumerator];
        NSString *fileName;
        unsignedlonglongint fileSize = 0;
        NSError* error;
        while (fileName = [filesEnumerator nextObject]) {
            NSDictionary* fileDictionary = [[NSFileManagerdefaultManager] attributesOfItemAtPath:[folderPath stringByAppendingPathComponent:fileName] error:&error];
            fileSize += [fileDictionary fileSize];
        } 
        
        return fileSize;
    }
    -(NSString *)getMPSize
    {
        NSString*sizeTypeW = @"bytes";
        int app = [self folderSize:@"/PathToTheFolderYouWantTheSizeOf/"];
        NSFileManager *manager = [NSFileManagerdefaultManager];
        if([manager fileExistsAtPath:@"/AnotherFolder/"] == YES){
            int working = [self folderSize:@"/AnotherFolder/"];
            if(working<1){
                return @"Size: Zero KB";
            }else{
                if (working > 1024)
                {
                    //Kilobytes
                    working = working / 1024;
                    
                    sizeTypeW = @" KB";
                }
                
                if (working > 1024)
                {
                    //Megabytes
                    working = working / 1024;
                    
                    sizeTypeW = @" MB";
                }
                
                if (working > 1024)
                {
                    //Gigabytes
                    working = working / 1024;
                    
                    sizeTypeW = @" GB";
                }
                
                return [NSStringstringWithFormat:@"App: %i MB, Working: %i %@ ",app/1024/1024, working,sizeTypeW];
            }
            
        }else{
            return [NSStringstringWithFormat:@"App: %i MB, Working: Zero KB",app/1024/1024];
        }
        [manager release];
    }
  • 相关阅读:
    记第一次重装系统
    数值运算_第1周
    更新驱动时显示失败,错误代码56
    Tomcat安装教程及常见错误解决方法
    中国学术界之特点
    Mac 安装qtbingdings出现error 解决方式
    关于xtea加密解密算法
    关于消息认证码
    2、关于协议数据包的设计
    关于协议标识符的实现方法
  • 原文地址:https://www.cnblogs.com/appwgh/p/2517541.html
Copyright © 2020-2023  润新知