To copy a directory in Ruby, you can use the FileUtils.cp_r
method provided by the FileUtils
module. This method allows you to recursively copy a directory and its contents. Here's an example:
main.rb124 chars5 lines
This will copy the directory source_dir
to destination_dir
, including all subdirectories and files. If the destination_dir
directory does not exist, it will be created.
You can also use the FileUtils.cp
method to copy a single file:
main.rb121 chars5 lines
Note that both FileUtils.cp_r
and FileUtils.cp
methods will replace any existing files or directories with the same name in the destination directory. If you want to avoid this, you can use the FileUtils.cp_r
method with a preserve
option:
main.rb201 chars6 lines
gistlibby LogSnag