将这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)