检查目录中是否存在某种文件类型的所有文件

use*_*161 3 python

我无法在python中检查某个文件类型的所有文件的目录,.wav是特定的.

我尝试了几种不同的方法来解决问题但似乎无法解决它.有没有办法在python中检查这样的目录?

Rob*_*son 5

这将列出所有文件名,然后检查它们是否以.wav结尾

import os

listdirectory = os.listdir(".") # gets the name of all files in your dir
for filename in listdirectory: 
    if filename.endswith(".wav"): # check each of the files for whether or not they end in .wav
Run Code Online (Sandbox Code Playgroud)