zoukankan      html  css  js  c++  java
  • python 遍历目录 正则

    20.5.101.31_/root>ls -ltr 10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-*
    -rw-r--r-- 1 root root 43206314 9月  20 18:44 10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000106.log.1.txt
    -rw-r--r-- 1 root root 86572354 9月  20 18:49 10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000106.log.1.pro
    -rw-r--r-- 1 root root    58030 9月  20 18:49 10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000106.log.1.fin
    -rw-r--r-- 1 root root    58030 9月  21 09:38 10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000106.log.1.fin1
    -rw-r--r-- 1 root root    58030 9月  21 09:38 10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000111.log.fin
    
    
    20.5.101.31_/root>cat a1.py
    # !/usr/bin/env python
    # -*- coding: utf-8 -*-
    import os
    import re
    import sys
    import time
    aaa=[]
    def listdir(path, list_name): #传入存储的list
     for file in os.listdir(path): 
       file_path = os.path.join(path, file) 
       if os.path.isdir(file_path): 
         listdir(file_path, list_name) 
       else: 
          list_name.append(file_path)
    listdir('/esb/logdir',aaa)
    print type(aaa)
    bbb=[]
    for x in aaa:
      if (re.search("fin$",x)):
         if (re.search('10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-',x)):
            print x
            bbb.append(x)
    print bbb
    print type(bbb)
    
    
    20.5.101.31_/root>python a1.py
    <type 'list'>
    /esb/logdir/10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000106.log.1.fin
    /esb/logdir/10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000111.log.fin
    ['/esb/logdir/10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000106.log.1.fin', '/esb/logdir/10106020180920010040173762-esbapp3-esb_in-20180920171404-405283-1300200000111.log.fin']
    <type 'list'>
  • 相关阅读:
    DataGrid
    取整、取小数点位数
    如何跨浏览器使用连续字符的换行
    如何给 legend 标签设定宽度
    25个简洁优美的网站设计
    重新发现HTML表格
    用户研究角度看设计(2):用户为何视若无睹
    lineheight 属性的继承问题
    jQuery技巧总结
    web2.0网站配色方案
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349050.html
Copyright © 2011-2022 走看看