- 思路:首先遍历循环文件夹,输出地址判断是否读对了文件,读取出文件中的内容,用正则匹配的模式匹配匹配出对应的字段,将两个匹配出来的列表字段合并,去重,写入目标文件夹中。
import re
import os
path = "D:\腾讯QQ\QQ下载\资源"
files = os.listdir(path)
allresult = []
for file in files:
position = path + '\\' + file
print(position)
f = open(position, "r", encoding='utf-8')
data = f.readlines()
pattern = re.compile('rsas_.\S*')
result = pattern.findall(str(data))
pattern2 = re.compile('RSAS_.\S*')
result2 = pattern2.findall(str(data))
allresult = allresult + result + result2
f.close()
print(set(allresult))
file = open('D:\腾讯QQ\QQ下载\表--多条去除.txt', 'w', encoding='utf-8')
file.write(str(set(allresult)))
file.close()