在指定目录下,模糊匹配搜寻目标文件,并得出目标文件的完整路径;
采用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====")
知行合一