Clumbsy error: check for dirs not files