Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

File Size With Error Handling

By: a guest on Jan 2nd, 2012  |  syntax: Objective C  |  size: 0.37 KB  |  views: 50  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. NSError *error = nil;
  2.  
  3. //Change YOUR_USERNAME with your username
  4. NSString *path = @"/Users/YOUR_USERNAME/Library/Safari/History.plist";
  5.  
  6. uint64_t fileSize = [[[NSFileManager defaultManager] attributesOfItemAtPath:path error:&error] fileSize];
  7.  
  8. if (error != nil) {
  9.         NSLog(@"Error: %@", [error localizedDescription]);
  10. } else {
  11.         NSLog(@"File Size: %.0llu", fileSize);
  12. }