Fixed a NPE

When scanning though the directories, it just rescanned the main directory and ended with a NPE or a StackOverflowException.