1
我想在* .log文件中記錄每個文件的差異在兩個目錄或文件夾之間進行文件比較。如何使用python 3.6.1比較2個目錄/文件夾,用於文件到文件(XML)的區別
我想在* .log文件中記錄每個文件的差異在兩個目錄或文件夾之間進行文件比較。如何使用python 3.6.1比較2個目錄/文件夾,用於文件到文件(XML)的區別
k=0
for i in dirs1:
for j in dirs2:
if i==j:
with open(os.path.join(path1,os.path.basename(i)), 'r') as f1:
with open(os.path.join(path2,os.path.basename(j)), 'r') as f2:
k+=1
print('TC'+str(k)+ ' started...')
print(os.path.join(path1,os.path.basename(i)), '\t',os.path.join(path2,os.path.basename(j)))
out_file.flush()
name1=os.path.basename(i)
name2=os.path.basename(j)
if name1==name2:
diff = difflib.ndiff(f1.readlines(), f2.readlines())
out_file.flush()
testPassed=None
#print lines with difference
for line in diff:
if line.startswith('-') and not(line.startswith('- <ID') or line.startswith('-Created :') or line.startswith('-Name=') or line.startswith('- <Information') or line.startswith('- ,,Date:') or line.startswith('- ,,,')):
testPassed=True
out_file.write(line)
out_file.flush()
elif line.startswith('+') and not(line.startswith('+ <ID') or line.startswith('+Created :') or line.startswith('+Name=') or line.startswith('+ <Information') or line.startswith('+ ,,Date:') or line.startswith('+ ,,,')):
testPassed=True
out_file.write(line)
out_file.flush()
if not testPassed ==True:
print('\tTC'+str(k)+' Passed for: %s\n' %i)
else:
print('\t\t***TC'+str(k)+' Failed for: %s ***\n' %i)
我需要通過在目錄中的所有文件一線之差線。 –