views:

996

answers:

2

I have a path to file contained in an NSString. Is there a method to get its file size?

+3  A: 

See sample code in FileManager's fileAttributesAtPath:traverseLink: documentation

thesamet
Thanks for the link!
hekevintran
+3  A: 

Bear in mind that fileAttributesAtPath:traverseLink: is deprecated as of Mac OS X v10.5. Use attributesOfItemAtPath:error: instead, described at the same URL thesamet mentions.

With the caveat that I'm an Objective-C newbie, and I'm ignoring errors that might occur in calling attributesOfItemAtPath:error:, you can do the following:

NSString *yourPath = @"Whatever.txt";
NSFileManager *man = [[NSFileManager alloc] init];
NSDictionary *attrs = [man attributesOfItemAtPath: yourPath error: NULL];
UInt32 result = [attrs fileSize];
Frank Shearar