Created
May 26, 2020 04:37
-
-
Save recursive-beast/bd40c9954d3302fd01d7583e25228098 to your computer and use it in GitHub Desktop.
Compare two directories recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import filecmp | |
def is_same_dirs(*args, dircmp: filecmp.dircmp = None) -> bool: | |
""" | |
Compare two directories recursively. | |
Files in each directory are assumed to be equal if their names and contents are equal. | |
:param dircmp: a filecmp.dircmp object that will be | |
used as the directory comparison object. | |
:returns: True if the directory trees are the same | |
and there were no errors while accessing the directories or files, | |
False otherwise. | |
""" | |
if not dircmp: | |
dircmp = filecmp.dircmp(*args) | |
if dircmp.left_only or dircmp.right_only or dircmp.diff_files or dircmp.funny_files: | |
return False | |
for sub_dircmp in dircmp.subdirs.values(): | |
if not is_same_dirs(dircmp=sub_dircmp): | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment