Filecmp module in Python provides functions to compare files and directories. This module comes under Python’s standard utility modules. This module also consider the properties of files and directories for comparison in addition to data in them.
filecmp.cmp() method in Python is used to compare two files. This method by default performs shallow comparison (as by default
shallow = True) that means only the
os.stat() signatures (like size, date modified etc.) of both files are compared and if they have identical signatures then files are considered to be equal irrespective of contents of the files. If
shallow is set to
False then the comparison is done by comparing the contents of both files.
Syntax: filecmp.cmp(file1, file2, shallow = True)
file1: The path of first file to be compared. It can be a string, bytes, os.PathLike object or an integer representing the path of the file.
file2: The path of second file to be compared. It can be a string, bytes, os.PathLike object or an integer representing the path of the file.
shallow (optional): A bool value ‘True’ or ‘False’. The default value of this parameter is True. If its value is True then only the metadata of files are compared. If False then the contents of the files are compared.
Return Type: This method returns a bool value True if specified files are equal or False if they are not.
- Difference between Method Overloading and Method Overriding in Python
- class method vs static method in Python
- Python | next() method
- Python | set() method
- Python | os.dup() method
- Python | os.open() method
- Python | os.sched_getaffinity() method
- Python | os.waitid() method
- Python | os.WIFEXITED() method
- Python | shutil.which() method
- Python | sympy.nT() method
- Python PIL | UnsahrpMask() method
- Python | sympy.apart() method
- Python | os.getcwd() method
- Python | os.ftruncate() method
- Python | os.truncate() method
- Python | os.major() method
- Python | os.minor() method
- Python | os.access() Method
- Python | os.utime() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.