python语言实现指定目录下正则匹配搜寻文件

在指定目录下,模糊匹配搜寻目标文件,并得出目标文件的完整路径;

采用match完全匹配;

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os 
import sys
import ctypes
import re

if __name__=="__main__":

    search_file_name_re_exp = ".*_file_.*"
    for root, dirs, files in os.walk(os.path.join(os.getcwd(),"search_root"), topdown=True):
        for item in files:
            match = re.match(search_file_name_re_exp, item, re.IGNORECASE)
            if match:
                print(match.group())
                print(os.path.join(root,match.group()))
            break
    print("====end====")

 

posted @ 2021-06-17 20:43  Grooovvve  阅读(962)  评论(0编辑  收藏  举报