python 递归遍历目录筛选特定文件名的文件
#!/usr/bin/python import os import sys list=[] folder_path="/root" def search_files(folder_path): search_string = "测试" for root, dirs, files in os.walk(folder_path): for name in files: if search_string in name: f = os.path.join(root, name) list.append(f) print(list) search_files(folder_path)
python 234.py
['/root/测试123.xlsx', '/root/123/测试99ee.xlsx', '/root/123/345/测试999.txt']