1

I need to differentiate between text file and image file without taking a look their path extension.

I would like to check if the file is actually the image or not. After searching, there is the way to check the mimetype from path extension, however, I would like the solution to verify the file's content itself.

Matthew Haugen
  • 12,916
  • 5
  • 38
  • 54
BB.
  • 707
  • 2
  • 11
  • 22
  • 1
    possible duplicate of [Get the type of a file in Cocoa](http://stackoverflow.com/questions/5814463/get-the-type-of-a-file-in-cocoa) – BergQuester Aug 18 '14 at 04:58
  • I've mentioned in the question description that I need the solution that doesn't take a look at their file extension. The solution in the suggested question doesn't answer my need because it consider file extension as a factor to say what file type it is. – BB. Aug 18 '14 at 09:56

1 Answers1

0
UIImage *image = [UIImage imageNamed:@"SomeFile.xyz"];
if (image == nil) {
    NSLog(@"This is probably text file");
}

If image is nil means the file may be text or another type of file.

Atif
  • 1,220
  • 11
  • 16