- (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]; }