FILECMP defines two functions for easy comparison of files and folders:
FILECMP.CMP (F1, f2[, shallow]):
Compares the contents of two files to match. Parameter F1, F2 specifies the path to the file to compare. Optional parameter shallow specifies whether to consider the properties of the file itself (through the Os.stat function to obtain file properties) when specifying the comparison file. If the contents of the file match, the function returns True, otherwise it returns false.
Filecmp.cmpfiles (Dir1, Dir2, common[, Shallow]):
Compares the specified files within two folders for equality. Parameter Dir1, DIR2 specifies the folder to compare, and the parameter common specifies the list of file names to compare. function returns a tuple containing 3 list elements, representing a matching, mismatched, and incorrect list of files. The wrong file refers to a nonexistent file, or a file that is not readable, or does not have permission to read the file, or cannot access the file for other reasons.
The FILECMP module defines a dircmp class for comparing folders, which compares two folders to get some detailed comparison results (such as a list of files that exist only in folder a) and supports recursive comparisons of subfolders.
DIRCMP provides three methods for reporting the results of comparisons:
report (): Only compare contents (Files and folders) in the specified folder
report_partial_closure (): Compare the contents of folders and first-level subfolders
report_full_closure (): Recursively compare the contents of all folders
DIRCMP also provides detailed results for comparing the following properties:
left_list: List of files and folders in the left folder;
right_list: List of files and folders in the right folder;
Common: Files or folders that exist on both sides of the folder;
left_only: Files or folders that exist only in the left folder;
right_only: Files or folders that exist only in the right folder;
Common_dirs: Subfolders that exist on both sides of the folder;
common_files: Files on both sides of the folder exist;
Common_funny: Subfolders that exist on both sides of the folder;
same_files: Matching files;
diff_files: Mismatched files;
funny_files: Files that exist on both sides of the folder but cannot be compared;
Subdirs: I didn't see the meaning of this attribute, as explained in the Python Manual: A Dictionary mapping names in Common_dirs to dircmp objects
Simplicity is beauty! I just need to compare the results of the file, do not want to care about how the file is compared, hey, use python bar ~ ~
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service