filecmp is a built-in Python module for checking whether files are identical. It helps prevent duplicate pictures when combining directories, but generated code and explanations still require testing. section 9.5.1 section 9.5.3
Compare two PNG files
Use filecmp.cmp(file1, file2) in a conditional to print whether two PNG files are the same. This example checks a pair of files; finding duplicates among hundreds requires iterating through directory contents. section 9.5.1
A directory-merging tool uses filecmp in a small sequence:
- List files in the target directory with os.listdir. section 9.5.3
- Test the program first with sample directories that are safe to alter. section 9.5.3
