Ensure the directory exists before adding it.