I implemented the solution of building an index of the files and then doing the for each, object in array type search through the list of filenames. It took my script from 10 seconds to less than a second because I need to do about 240 matches each time I run the script.
Something that is worth mentioning is that if you want your indexing loop to go faster or if you don't want to match the shortname of the file name (annoying!) then do the index loop like below. Also, don't use A_loopfilelongpath as it has to do extra conversions than A_LoopFileLongPath!
Code: Select all
;build folder list takes takes 200-300 ms
word_files :=[]
loop, M:\* , 0 , 1
{
if instr(A_LoopFileName, "~");this part skips recording the short names
continue
word_files.Insert({path:A_LoopFileFullPath})
}
Code: Select all
find_word_file(section_number) {
global
for index, file in word_files
{
if instr(file.path, product "-" section_number ".doc")
return file.path
}
}