Fix crash calling openDirectories() in various cases
This can cause a crash when called with a single url and split view, or
when the last URL is not shown, because it
gets mutated in the loop,
so we need to make sure it hasn't gone out of bounds. This check was
erroneously removed in 17553802 and
needs to be brought back.
Edited by Nate Graham