# 对比两个文件中相同名称的TXT是否相同
def check(ff01,ff02):
# print(ff02)
# 判断文件共有几行
num=0
with open(ff01) as file01:
for line in file01:
num = num + 1
with open(ff01, 'r') as x , open(ff02, 'r') as y:
line1 = x.readlines()
line2 = y.readlines()
for i in range(num):
va1 = line1[i].rstrip()
va2 = line2[i].rstrip()
if va1[:-8] == va2[:-8]: #去除某一行后8位
print("本行相同")
else:
var = str(i + 1)
print("第" + var + "行不同。")
print(va1[:-8])
print(va2[:-8])
# check('d://test01.txt','d://test02.txt')
def path(path01,path02):
import os
# rootdir01 = 'd://Test/test01'
# rootdir02 = 'd://Test/test02'
list01 = os.listdir(path01) # 列出文件夹下所有的目录与文件
list02 = os.listdir(path02)
print(list01)
print(list02)
for i in range(len(list01)):
if list01[i] not in list02:
file = open(path02 + '/' + list01[i], 'w')
file.write('6666,6666,666666')
file.close()
check(path01 + '/' + list01[i] , path02 + '/' + list01[i])
print("=======以上是"+list01[i]+"=================")
path('D://Test/test01' , 'D://Test/test02')
加载中,请稍候......