python读取目录下的相似文件进行合并

 

将这5个文件夹合并到sdf.txt文件中


import re

from envs.django.Lib import os

if __name__ == '__main__':

f1 = open('d:/englishbook/sdf.txt', 'a+', encoding='UTF-8')
path = 'D:\englishbook'
filelist = os.listdir(path)
print(filelist)
for i in filelist:
an = re.search('^[Tech\d\.txt]+$', str(i))
print(i)
print(an)
if an:
with open('d:/englishbook/'+str(i), 'a+', encoding='UTF-8') as file1:
print('d:/englishbook/'+str(i))
file1 = open('d:/englishbook/'+str(i), 'a+', encoding='UTF-8')
file1.seek(0)
contents = file1.read()
f1.write(contents)
posted @ 2018-11-26 17:18  lqybetter  阅读(814)  评论(0编辑  收藏  举报