![]() ![]() New_dir2 = os.path.join(dir2, common_dir) New_dir1 = os.path.join(dir1, common_dir) (_, mismatch, errors) = filecmp.cmpfiles(ĭir1, dir2, dirs_cmp.common_files, shallow=False) 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. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |