Sunday, April 21, 2013

NSFileManager contentsEqualAtPath example objc


contentsEqualAtPath :andPath:

Returns a Boolean value that indicates whether the files or directories in specified paths have the same contents.
- (BOOL)contentsEqualAtPath:(NSString *)path1 andPath:(NSString *)path2
Parameters
path1
The path of a file or directory to compare with the contents of path2.
path2
The path of a file or directory to compare with the contents of path1.
Return Value
YES if file or directory specified in path1 has the same contents as that specified in path2, otherwise NO.
Discussion of [NSFileManager contentsEqualAtPath]
If path1 and path2 are directories, the contents are the list of files and subdirectories each contains—contents of subdirectories are also compared. For files, this method checks to see if they’re the same file, then compares their size, and finally compares their contents. This method does not traverse symbolic links, but compares the links themselves.
Example of [NSFileManager contentsEqualAtPath]

NSFileManager *filemgr;

filemgr = [NSFileManager defaultManager];

if ([filemgr contentsEqualAtPath: @"/tmp/myfile.txt" andPath: @"/tmp/sales.txt"] == YES)
        NSLog (@"File contents match");
else
        NSLog (@"File contents do not match");