From 82a2b62578a791499c60ef3a26ffd3b53f75052a Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Tue, 14 Jun 2022 15:42:23 -0500 Subject: [PATCH] [DOC] More on cp_r (#87) * More on cp_r --- lib/fileutils.rb | 63 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/lib/fileutils.rb b/lib/fileutils.rb index 81c5e31..f257abb 100644 --- a/lib/fileutils.rb +++ b/lib/fileutils.rb @@ -817,9 +817,10 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil) alias copy cp module_function :copy - # Recursively copies files from +src+ to +dest+. + # Recursively copies files. # - # Arguments +src+ and +dest+ + # Arguments +src+ (a single path or an array of paths) + # and +dest+ (a single path) # should be {interpretable as paths}[rdoc-ref:FileUtils@Path+Arguments]. # # If +src+ is the path to a file and +dest+ is not the path to a directory, @@ -841,31 +842,53 @@ def cp(src, dest, preserve: nil, noop: nil, verbose: nil) # If +src+ is the path to a directory and +dest+ does not exist, # recursively copies +src+ to +dest+: # - # FileUtils.mkdir_p(['src2/dir0', 'src2/dir1']) - # FileUtils.touch('src2/dir0/src0.txt') - # FileUtils.touch('src2/dir0/src1.txt') - # FileUtils.touch('src2/dir1/src2.txt') - # FileUtils.touch('src2/dir1/src3.txt') + # tree('src2') + # src2 + # |-- dir0 + # | |-- src0.txt + # | `-- src1.txt + # `-- dir1 + # |-- src2.txt + # `-- src3.txt + # FileUtils.exist?('dest2') # => false + # # FileUtils.cp_r('src2', 'dest2') - # File.exist?('dest2/dir0/src0.txt') # => true - # File.exist?('dest2/dir0/src1.txt') # => true - # File.exist?('dest2/dir1/src2.txt') # => true - # File.exist?('dest2/dir1/src3.txt') # => true + # tree('dest2') + # dest2 + # |-- dir0 + # | |-- src0.txt + # | `-- src1.txt + # `-- dir1 + # |-- src2.txt + # `-- src3.txt # # If +src+ and +dest+ are paths to directories, # recursively copies +src+ to dest/src: # - # FileUtils.mkdir_p(['src3/dir0', 'src3/dir1']) - # FileUtils.touch('src3/dir0/src0.txt') - # FileUtils.touch('src3/dir0/src1.txt') - # FileUtils.touch('src3/dir1/src2.txt') - # FileUtils.touch('src3/dir1/src3.txt') + # tree('src3') + # src3 + # |-- dir0 + # | |-- src0.txt + # | `-- src1.txt + # `-- dir1 + # |-- src2.txt + # `-- src3.txt # FileUtils.mkdir('dest3') + # # FileUtils.cp_r('src3', 'dest3') - # File.exist?('dest3/src3/dir0/src0.txt') # => true - # File.exist?('dest3/src3/dir0/src1.txt') # => true - # File.exist?('dest3/src3/dir1/src2.txt') # => true - # File.exist?('dest3/src3/dir1/src3.txt') # => true + # tree('dest3') + # dest3 + # `-- src3 + # |-- dir0 + # | |-- src0.txt + # | `-- src1.txt + # `-- dir1 + # |-- src2.txt + # `-- src3.txt + # + # If +src+ is an array of paths and +dest+ is a directory, + # recursively copies from each path in +src+ to +dest+; + # the paths in +src+ may point to files and/or directories. # # Keyword arguments: #