我想只获取.wav结尾的文件该怎么写

import os

labsIndName=[]
num_class=0
def create_datasets():
    path="I:\\pycham\\PyCharm 2020.2.3\\语音识别\\数据集\\data_thchs30\\"
    dirs = os.listdir(path) # 获取的是目录列表
    for i in dirs:
        print("开始加载:",i)
        labsIndName.append(i) # 当前分类进入到标签的名字集
        wavs_path=path+"\\"+i
        testNum=0 # 当前分类进入了测试集的有几个 ,这里暂定每个分类进100个到测试集
        files = os.listdir(wavs_path) # 某个目录下文件的列表
        for j in files:
            
            print(j)
create_datasets()

import os
import string

inputFilePath= "I:\\pycham\\PyCharm 2020.2.3\\语音识别\\数据集\\data_thchs30\\"
threefile = [ ]
for file in os.listdir(inputFilePath):
    if os.path.splitext(file)[1] == '.wav':  
            sourcefile = os.path.join(inputFilePath, file)  
            threefile.append(sourcefile)
print threefile

您好,我是问答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~