Extract extension discovery method.
Replace scandir with DirectoryIterator.