Python listdir只展示指定类型的文件

def formPMStrgetOldName(PMStr):
    rootPath = r'D:\x\s\d\d'
    dirs = os.listdir(rootPath)
    for i in dirs:  # 循环读取路径下的文件并筛选输出
        if os.path.splitext(i)[1] == ".csv" and (PMStr in i):  # 筛选csv文件
            return i
posted @ 2021-01-21 16:40  bH1pJ  阅读(392)  评论(0编辑  收藏  举报