import os
file_path = r'*********' # 序列文件路径
for parent, dirnames, filenames in os.walk(file_path): # 遍历路径下全路径
for filename in filenames: # 遍历全路径下全文件名
full_path = os.path.join(parent, filename) # 组装完整文件路径
print(full_path)
file_read = open(full_path, mode='r', encoding='utf8') # 读取路径内容
print(file_read.readline())
file_write = open('merge_data.txt', 'a', encoding='utf8') # 创建写入对象,按全量方式写入
file_write.writelines(file_read) # 将读取的内容合并写入新的文件
file_read.close()
file_write.close()
网友评论