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'>
  • 相关阅读:
    剑指offer 39. 是否为平衡二叉树
    剑指offer 38. 二叉树的深度
    剑指offer 16. 合并两个有序链表
    剑指offer 15.链表反转
    剑指offer 58.对称的二叉树
    剑指offer 62. 二叉搜索树的第 k 个结点
    二叉树的前序和中序遍历的非递归实现
    将求模运算转换成与运算,加快运算速度
    Java中数字的格式化输出
    Java中的freopen()
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13349050.html
Copyright © 2011-2022 走看看