tags:

views:

48

answers:

2

Hello,

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,

+2  A: 

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];
Vladimir
thanks for your replay but i have one question can i get creation date of file?
milanjansari
See this question - http://stackoverflow.com/questions/1140696/cant-get-filecreationdate, this key may be not supported in iPhoneOS
Vladimir
A: 

thanks for your replay but i have one question can i get creation date of file?

i am trying to below of the code.

creationDate = [attributes objectForKey:NSFileCreationDate];

but every time getting null value

can you please help me.

milanjansari
Do a NSLog(@"attributes %@", attributes); to check what's in your dictionary.
yonel