From: https://mp.weixin.qq.com/s/RxyRU5kYvYJ3Wb4I86Vx6A
---------------------------------------------------------------------------------------
import glob
class Test_Find_File:
def test_find_file(pattern, path='.'):
"""
按照文件名查找文件
:param pattern: 文件名模式,例如 "*vft*.pdf,文件名包含vft的pdf文件"
:param path: 查找的目录路径,默认为当前目录
:return: 匹配到的文件列表
"""
return glob.glob(f'{path}/**/{pattern}', recursive=True)
file_list = test_find_file("*.pdf", 'D:\\sli_dev1\\GW2\\test_pdf_files\\')
n = 0
for file_path in file_list:
print(file_path)
n += 1
print("total files: " + str(n))