Full File Comparisons

If you simply want to compare whether two files are identical, is it best to use the Compare or string.compare function?

Do you first have to cffile read the contents to compare? Or can any of the compare functions reference two files on disk?

These would be rather small files (i.e. ~168 bytes) in this scenario, just FYI.

I believe compare() or string.compare() are the same function, behind the scene.
The second is the “member method” function.

1 Like

I’m not aware of any core function in Lucee for directly comparing files.

Compare() does more than what you need.

Here’s how I would do it very simply in cfscript:

dump(FileContentsAreSame(yourfile1, yourfile2));

public boolean function FileContentsAreSame(path1, path2) {
	var str1 = FileRead(path1);
	var str2 = FileRead(path2);
	return str1 == str2;
}