3

I just want to know if one text file equal to another. Of course I can load files to NSString and compare them, but is there a better way?

DavidG
  • 113,891
  • 12
  • 217
  • 223
Dmitriy
  • 1,898
  • 1
  • 15
  • 24
  • you could check file size first using [NSFileManager fileSsystemAttributesAtPath] - if the same, then compare contents – Mike M Dec 30 '14 at 13:39

1 Answers1

8

Have a look at the NSFileManager documentation. There is a method which will complete your task I think:

NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];

if ([filemgr contentsEqualAtPath: @"/path/to/file1.txt" andPath: @"/path/to/file2.txt"] == YES) {
    //MATCH
}
dehlen
  • 7,325
  • 4
  • 43
  • 71