Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
FileUtils#copy_file
(::FileUtils::path src, ::FileUtils::path dest, ?::boolish preserve, ?::boolish dereference) -> void
copy_file(src, dest, preserve = false, dereference = true)
lib/fileutils.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/fileutils.rb, line 1102
def copy_file(src, dest, preserve = false, dereference = true)
ent = Entry_.new(src, nil, dereference)
ent.copy_file dest
ent.copy_metadata dest if preserve
end
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
Optional arguments:
-
dereference- ifsrcis a symbolic link, follows the link (trueby default). -
preserve- preserves file times (falseby default). -
remove_destination- removesdestbefore copying files (falseby default).
Related: methods for copying.