class method
FileUtils.link_entry
(::FileUtils::path src, ::FileUtils::path dest, ?::boolish dereference_root, ?::boolish remove_destination) -> void
link_entry(src, dest, dereference_root = false, remove_destination = false)
lib/fileutils.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/lib/fileutils.rb, line 809
def link_entry(src, dest, dereference_root = false, remove_destination = false)
Entry_.new(src, nil, dereference_root).traverse do |ent|
destent = Entry_.new(dest, ent.rel, false)
File.unlink destent.path if remove_destination && File.file?(destent.path)
ent.link destent.path
end
end
Creates hard links; returns nil.
Arguments src and dest should be interpretable as paths.
If src is the path to a file and dest does not exist, creates a hard link at dest pointing to src:
Example
FileUtils.touch('src0.txt') File.exist?('dest0.txt') # => false FileUtils.link_entry('src0.txt', 'dest0.txt') File.file?('dest0.txt') # => true
If src is the path to a directory and dest does not exist, recursively creates hard links at dest pointing to paths in src:
Example
FileUtils.mkdir_p(['src1/dir0', 'src1/dir1']) src_file_paths = [ 'src1/dir0/t0.txt', 'src1/dir0/t1.txt', 'src1/dir1/t2.txt', 'src1/dir1/t3.txt', ] FileUtils.touch(src_file_paths) File.directory?('dest1') # => true FileUtils.link_entry('src1', 'dest1') File.file?('dest1/dir0/t0.txt') # => true File.file?('dest1/dir0/t1.txt') # => true File.file?('dest1/dir1/t2.txt') # => true File.file?('dest1/dir1/t3.txt') # => true
Optional arguments:
-
dereference_root- dereferencessrcif it is a symbolic link (falseby default). -
remove_destination- removesdestbefore creating links (falseby default).
Raises an exception if dest is the path to an existing file or directory and optional argument remove_destination is not given.
Related: FileUtils.ln (has different options).