Fixed if to check for directories not files