Extract repeated filename finding code into function.