Matt S.
Matt S.

Reputation: 13773

iphone sdk see size of local file (one created by application)

How can I look at the size of a file the application creates in bytes?

Upvotes: 3

Views: 4723

Answers (1)

nduplessis
nduplessis

Reputation: 12436

Use NSFileManager class' method

- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error

The size key in the returned dictionary is defined as

NSString * const NSFileSize;

So for an example

NSError *error = nil;
NSDictionary *attributes = [[NSFileManager defaultManager] 
    attributesOfItemAtPath:@"/path/to/file" error:&error];

if (!error) {
    NSNumber *size = [attributes objectForKey:NSFileSize];
}

Upvotes: 22

Related Questions