码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2018-11-26 20:19:27      阅读:251      评论:0      收藏:0      [点我收藏+]

标签:str   enc   文件夹   django   读取   分享图片   imp   image   分享   

 

技术分享图片

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

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

标签:str   enc   文件夹   django   读取   分享图片   imp   image   分享   

原文地址:https://www.cnblogs.com/cunlqy/p/10021546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!