Added support for creating intermediate directories if they are missing.