Handle directories more intelligently