Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

class method

FileUtils.copy_entry

copy_entry(src, dest, preserve = false, dereference_root = false, remove_destination = false)

Recursively copies files from src to dest.

Arguments src and dest should be interpretable as paths.

If src is the path to a file, copies src to dest:

Example
FileUtils.touch('src0.txt')
File.exist?('dest0.txt') # => false
FileUtils.copy_entry('src0.txt', 'dest0.txt')
File.file?('dest0.txt')  # => true

If src is a directory, recursively copies src to dest:

Example
tree('src1')
# => src1
#    |-- dir0
#    |   |-- src0.txt
#    |   `-- src1.txt
#    `-- dir1
#        |-- src2.txt
#        `-- src3.txt
FileUtils.copy_entry('src1', 'dest1')
tree('dest1')
# => dest1
#    |-- dir0
#    |   |-- src0.txt
#    |   `-- src1.txt
#    `-- dir1
#        |-- src2.txt
#        `-- src3.txt

The recursive copying preserves file types for regular files, directories, and symbolic links; other file types (FIFO streams, device files, etc.) are not supported.

Keyword arguments:

  • dereference_root: true - if src is a symbolic link, follows the link.

  • preserve: true - preserves file times.

  • remove_destination: true - removes dest before copying files.

Related: methods for copying.

See also #copy_entry .copy .copy_file .compare_stream also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0