Case 1:
Compare two files
Example:
# if they have the same content, return True
import filecmp
filecmp.cmp("c:/testFolder1/test1.txt", "c:/testFolder1/test2.txt")
Case 2:
Compare two directories
Example:
import filecmp
cmp = filecmp.dircmp('c:/testFolder1/', 'c:/testFolder2/')
# print out result
cmp.report()
# get the first directory
cmp.left
# get the second directory
cmp.right
# get the contents underneath the first directory
cmp.left_list
# get the contents underneath the second directory
cmp.right_list
# get the files or subdirectories in both directories.
cmp.common
# get common files only
cmp.common_files
# get common subdirectories only
cmp.common_dirs
No comments:
Post a Comment