d1_contents = set(os.listdir(r'C:\Users\AUTHORITAH\Desktop\comp_2'))
d2_contents = set(os.listdir(r'E:\comp_1'))
common = list(d1_contents & d2_contents)
common_files = [ f
for f in common
if os.path.isfile(os.path.join(r'C:\Users\AUTHORITAH\Desktop\comp_2', f))
]
print ('Common files:', common_files)
match, mismatch, errors = filecmp.cmpfiles(r'C:\Users\AUTHORITAH\Desktop\comp_2',
# r'E:\comp_1',
#common_files)
print ('Match:', match)
print ('Mismatch:', mismatch)
print ('Errors:', errors)
我正在尝试比较两个目录的内容,如果我将新数据添加到dir 1中,它应该被添加到dir 2.对于ex-如果dir 1中有8个文件,我在其中再添加2个,然后dir 2也应该更新这2个新文件。