all Python 3filecmpfunction
filecmp.cmpfiles()
comparing files
Compares same-named files in two directories and splits the names into three lists: match, mismatch, errors.
Syntax
match, mismatch, errors = filecmp.cmpfiles(a, b, common, shallow=True)
It returns a tuple (match, mismatch, errors). Names come from the third argument, not from the directories: anything not listed is not compared. A file missing on either side goes to errors, while a subdirectory with that name lands in mismatch. shallow=True, as in cmp(), trusts size and mtime.
Examples
import filecmp, os
os.makedirs('L'); os.makedirs('R')
for d, text in (('L', 'aa'), ('R', 'bbb')):
open(f'{d}/same.txt', 'w').write('1')
open(f'{d}/diff.txt', 'w').write(text)
print(filecmp.cmpfiles('L', 'R', ['same.txt', 'diff.txt', 'ghost.txt'], shallow=False)) # → (['same.txt'], ['diff.txt'], ['ghost.txt'])
See also
Open in the full glossarydocs.python.orgReport an inaccuracy