dir1 = r'C:\Program Files\AnsysEM\AnsysEM20.1'
dir2 = r'C:\Program Files\AnsysEM\AnsysEM20.2'
outputtxt = 'd:/demo/compare.txt'
import os
from filecmp import dircmp
result_right=[]
result_left=[]
def print_diff_files(dcmp):
global result_right, result_left
for name in dcmp.right_only:
result_right.append('{}\\{}\n'.format(dcmp.right, name))
for name in dcmp.left_only:
result_left.append('{}\\{}\n'.format(dcmp.right, name))
for sub_dcmp in dcmp.subdirs.values():
print_diff_files(sub_dcmp)
dcmp = dircmp(dir1, dir2)
print_diff_files(dcmp)
with open(outputtxt, 'w') as f:
f.writelines(result_left)
f.writelines('-'*120+'\n')
f.writelines(result_right)
os.system('notepad++ d:/demo/compare.txt')
(圖一) 兩個目錄之間檔案差異比較 |
沒有留言:
張貼留言