# _*_coding: utf-8_*_
import numpy as np
import os
import sys
def listDirectory(path,list_path,filetype):
for file in os.listdir(path):
file_path=os.path.join(path,file)
if os.path.isdir(file_path):
continue
elif os.path.splitext(file_path)[1]==filetype:
list_path.append(file_path)
def getLastLine(file_name):
cmd = "tail -n 2 "+ file_name
index = file_name.split("time")[-1].split(".txt")[0]
#last_line = os.system("echo -e "+ "` "+ cmd + " `")
cmd2 = 'echo -e '+str(index)+' ` '+ cmd +' `' + ' >> summary.log'
os.system(cmd2)
if __name__=='__main__':
path = sys.argv[0]
# path_data=os.path.abspath(os.path.join(os.getcwd()))
path_data=os.path.abspath(os.path.join(os.getcwd(),'./time/'))
filetype=['.txt']
data_list_path=[]
listDirectory(path_data,data_list_path,filetype[0])
for file_name in data_list_path:
getLastLine(file_name)
os.system("sort -k 1 summary.log > summary.txt")
标签:name,python,data,list,一行,获取,file,path,os
From: https://www.cnblogs.com/WEIWEI1095/p/17753711.html