Typically it's up to you to make sure that the target directory path exists, so I doubt if any built-in command does what you're looking for.
But using FileUtils.mkdir_p(dir)
could be very straightforward, especially by using File.dirname()
to parse the path. You could even wrap it in a utility routine, e.g.:
require 'fileutils'
def copy_with_path(src, dst)
FileUtils.mkdir_p(File.dirname(dst))
FileUtils.cp(src, dst)
end
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…