Added check for thisDir == null
Reworked to use regular expressions