Skip to content

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

instance method

FileUtils#copy_file

copy_file(src, dest, preserve = false, dereference = true)

Copies file from src to dest, which should not be directories.

Arguments src and dest should be interpretable as paths.

Examples:

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

Keyword arguments:

  • dereference: false - if src is a symbolic link, does not follow the link.

  • preserve: true - preserves file times.

  • remove_destination: true - removes dest before copying files.

Related: methods for copying.

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