0

I have a directory with a lot of audio files and a list that contains the names of some of these files. I want to process only the files in the directory that are matching with my name list.

My attempt (that is not working) is this:

path_to_audio_files = 'D:/Data_small/output_conv/'
sample_list = ['s1.wav', 's2.wav', 's3.wav']

import fnmatch

for file in os.listdir(path_to_audio_files):
    if fnmatch.fnmatch(file, sample_list):
        fs, signal = wavfile.read(file)

Is this even the right way to do it or how can it be done? Thanks!

Alex905
  • 25
  • 3

1 Answers1

0

Why use fnmatch (I have never heard of it) instead of python native capabilities? (in operator)

path_to_audio_files = 'D:/Data_small/output_conv/'
sample_list = ['s1.wav', 's2.wav', 's3.wav']

for file in os.listdir(path_to_audio_files):
    if file in sample_list:
        fs, signal = wavfile.read(file)
Wasif
  • 14,755
  • 3
  • 14
  • 34
  • That is what I'm looking for. I'm a beginner in python and didn't know that I just can use the 'in' operator. I read in another post about the 'fnmatch' and thought it could be used in my case. Anyways, thank you! – Alex905 Dec 08 '20 at 16:18