Create missing directories when needed.