Added check for directory before chmod.