zoukankan      html  css  js  c++  java
  • 获取文件夹大小

    - (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];
    }
  • 相关阅读:
    第二百三十四天 how can I 坚持
    第二百三十三天 how can I 坚持
    第二百三十二天 how can I 坚持
    第二百三十一天 how can I 坚持
    第二百三十天 how can I 坚持
    第二百二十九天 how can I 坚持
    第二百二十八天 how can I 坚持
    第二百二十七天 how can I 坚持
    GG's Single Day
    杭电2133--What day is it
  • 原文地址:https://www.cnblogs.com/appwgh/p/2517541.html
Copyright © 2011-2022 走看看