Automatically create the target directory if it doesn't exist.

Error messages are also adjusted accordingly.