读取文件夹内一个txt文件
记录txt文件名(用户ID)
写入到一个新的txt文件内
原txt文件删掉
以上步骤循环
txt文件按内容里时间排序
每条日志开头添加 用户ID + 原内容
我想大声告诉你2017-05-18 10:56:10
python2.7语法, py3请自行相应改下
import glob
import os
src_dir = '/root/*.txt' # 利用通配符查找后缀名为txt的文件
dest_file = 'result.txt'
with open(dest_file, 'w') as f_w:
for file_name in glob.glob(src_dir):
with open(file_name) as f_r:
for line in f_r:
f_w.write('%s %s' % (file_name, line))
os.remove(file_name)