Have a look at this post, it contains information on how to recursively look for files in a directory. So you could look for each of the wav files like this:
import os
def find_file(root_dir, filename):
for root, dirs, files in os.walk(root_dir):
for file in files:
if file == filename:
return True # return true if file was found
print("Not found: " + filename) # print full path
return False # return false if file was not found
for wav_file in wav_file_list:
find_file(parent_dir, wav_file)
If you have a lot of files and directories, you might want to put all wav files into a set to speed up the lookup, otherwise you script might take a long time to run.
Create the set like this:
import os
def find_all_wav_files(root_dir):
wav_files = set()
for root, dirs, files in os.walk(root_dir):
for file in files:
if file.endswith(".wav"):
wav_files.add(os.path.join(root, file))
return wav_files
You can then check if the wav files exist like this:
wav = parse_your_docx(docx_file)
wav_files = find_all_wav_files("your/sound/directory")
for w in wav:
if w in wav_files:
print(w + " exists!")
else:
print(w + " does not exist!")
The function find_all_wav_files()
will return a set of all wav files in the directory you specify as first argument. You can then search it like a list as shown in the second code snippet.