create output dir if necessary and correctly join paths