I am trying to fetch the file size attribute from a NSURL object by passing it getResourceValue:forKey method. Here is the code i am writing:
NSURL *samplePath = [[NSURL alloc] initWithString:@"file://localhost/Users/Abhinav/Test/abhi.pdf"];
[samplePath getResourceValue:&name forKey:NSURLFileSizeKey error:&error];
NSLog(@"Error===%@",error);
NSLog(@"name===%@",name);
But i am getting following error:
Error Domain=NSPOSIXErrorDomain Code=17 "The operation couldn’t be completed. File exists"
Please assist.
If you are trying to get the file size of a local file, see NSFileManager
For example, to get the size of a file:
int size = [[[NSFileManager defaultManager] attributesOfItemAtPath:@"/Users/Abhinav/Test/abhi.pdf" error:NULL] fileSize];should work (and will setsizeto0if the file does not exist, or is not readable).