Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

FileUtils.copy_file

(::FileUtils::path src, ::FileUtils::path dest, ?::boolish preserve, ?::boolish dereference) -> void
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.3 · 3.2 · 3.1 · 3.0