Python 获取文件夹里所有 log 的起止时间戳

 

import sys, os

def get_timestamp(file_name):
    cnt = 0;
    with open(file_name,"r") as f: 
        for line in f.readlines():
            line = line.strip()      
            #print (line)
            if(cnt == 0):
                start = line[1:10];
            cnt = cnt + 1
        end = line[1:10];                    
        print ("File: %s, Start %s, End %s\n" %(file_name, start, end))
        #print(start)
        #print(end)

def loop_over(dir):
    files = os.listdir(dir)
    for file in files:
        if not file.endswith('.log'):
            continue
        get_timestamp(file)

def main(argv):
    loop_over(argv[1])


if __name__ == '__main__':
    main(sys.argv)

 

posted on 2020-12-03 13:22  liujx2019  阅读(565)  评论(0编辑  收藏  举报

导航