Raul2018

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

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))
posted on 2024-05-22 20:55  Raul2018  阅读(9)  评论(0编辑  收藏  举报