The existing code lists the directory contents 7 times. This usually isn't a big deal, but I'm running Octoprint on a really slow ARM board, so this ends up taking 123ms (coming out to 17ms per call). We can speed this up a lot by only listing the files once, and searching through them. With this change, this function is fast enough that it doesn't show up in the profiler