NSArray *pathArr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

path = [[pathArr objectAtIndex:0]stringByAppendingPathComponent:[NSString stringWithFormat:@"imagename.png"]];  // Getting the path of the image, whose size is to be calculated.

NSFileManager *fileManager = [NSFileManager defaultManager]; // Creating the object of file manager.

NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:path traverseLink:YES]; // Getting the attributes of the file in the path.

if(fileAttributes != nil)

{

NSString *fileSize = [fileAttributes objectForKey:@"NSFileSize"]; // Getting the value corresponding to the key NSFileSize from the attributes array and storing it to a string..

NSLog(@"File size: %@ kb", fileSize);

}

Tagged with:

Filed under: Box 2dCocoaCocos2diPadiPhoneObjective CTips and Tricks

Like this post? Subscribe to my RSS feed and get loads more!