# -*- coding: utf-8 -*-
"""
Created on Thu Jul 8 13:08:46 2021
@author: haijiao
用于把多个txt文件合并为一个txt文件
filt_path填所要合并txt文件的目录
path_merges填输出文件目录
out_file_path最后为合并后txt的名字
"""
import os
file_path = "./"
path_merges = "./results_merges"
out_file_path = os.path.join(path_merges, 'train.txt')
file_list = os.listdir(file_path)
txt_list = []
data_list = []
if not os.path.exists(path_merges):
os.mkdir(path_merges)
if os.path.exists(out_file_path):
os.remove(out_file_path)
for file in file_list:
if file.endswith(".txt"):
txt_list.append(file)
print(txt_list)
for txt_file in txt_list:
with open(os.path.join(file_path, txt_file), 'r') as f:
data = f.read()
with open(out_file_path,"a") as f1:
f1.write(data)
10-11
2173