Added directory permission check.