Bootstrap FreeKB - Python (Scripting) - List differences between files using filecmp
Python (Scripting) - List differences between files using filecmp

Updated:   |  Python (Scripting) articles

The filecmp (File Compare) module can be used to compare files, to determine if the files are the same or if the files contain differences. For example, to compare /tmp/foo.txt to /tmp/bar.txt.

  • If the files are the same (no differences) True should be returned.
  • If the files contain differences, False should be returned
#!/usr/bin/python3
import filecmp
result = filecmp.cmp("/tmp/foo.txt", "/tmp/bar.txt")
print(f"result = {result}")

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter fb73f0 in the box below so that we can be sure you are a human.