
If len(dirs_cmp.left_only)>0 or len(dirs_cmp.right_only)>0 or \ There were no errors while accessing the directories or files, Files in each directory areĪssumed to be equal if their names and contents are dir1: First directory dir2: Second directory True if the directory trees are the same and import filecmpĬompare two directories recursively.

In the implementation below, when comparing files with the same name, we're always comparing only their contents. However, it does not recurse simply by using common_dirs and subdirs attributes since in that case we would be implicitly using the default "shallow" implementation of files comparison, which is probably not what you want. It uses a recursion instead of os.walk, so it is a little simpler.

Here's an alternative implementation of the comparison function with filecmp module.
