Replace `opendir`, `readdir` and `while` loop with `glob`