Python Example | Get All WAV Files in a Directory

This python example code will show us how to get all wav files in a directory using python.

import pathlib
import os

def getFiles(path='.', filetype = ".py", include_subdir = False):
    pattern = '*'
    if include_subdir:
       pattern = '**/*'
    files = pathlib.Path(path).glob(pattern+filetype)
    return files

dir = r'E:\CASIA database'

all_files = file_util.getFiles(path=dir, filetype = ".wav", include_subdir = True)
for wav_file in all_files:
    wav_file = str(wav_file)
    print(wav_file)

If you want to list all fines in a directory, you can read this example:

Python Example | Get All Files in Directory and Sub Directories