Fix submodule sort order during iteration

It turns out that #2205 introduced a bug where submodules were being sorted as if their name ended in a `/`. The name was fixed before the actual comparison was done, but the ordering was incorrect, so if you had a submodule named `foo` and a file named `foo-bar` the submodule was being processed after the file instead of before.

This PR moves the iterator submodule check to the point of scanning the directory (effectively where it used to be before #2205) and out of the processing of each individual item.