Instead of calling `utils.readdir()` twice to get directories and files, we now read the directory only once and sort it by item type. Also optimizes extension checking. ref #344