milanjansari
milanjansari

Reputation: 1549

Get file property

How to get file size of pdf,gif,doc etc using xcode. suppose to i get pdf file form resorce folder so how can i get size of for this file.

is there any way?

Thanks you,

Upvotes: 0

Views: 452

Answers (1)

Vladimir
Vladimir

Reputation: 170849

If you want to calculate the size of your resource file in run-time basically you can do the following (omitting error checks etc):

// Get path for resource file
NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"myPDFFile" ofType:@"pdf"];
// Get file attributes
NSDictionary* attributeDict = [[NSFileManager defaultManager] attributesOfItemAtPath:resourcePath error:nil];
// Get size attribute
NSNumber* fileSizeObj = [attributeDict objectForKey:NSFileSize];
long long fileSizeVal = [fileSizeObj lonLongValue];

Upvotes: 2

Related Questions