I’m trying to copy the entire contents of one directory to another:
source = "/var/www/html/sites/demo"
dest = “var/www/html/sites/newsite”
The source directory contains a file, index.html, and a directory
cgi-bin, which contains some scripts and such.
What I want is for the ‘dest’ to have a complete copy of everything in
’source’ with all the files in ‘source’ in ‘dest’ and any
subdirectories of ‘source’ copied to ‘dest’ with all their contents,
recursively.
When I use:
FileUtils.cp_r( source, dest )
I end up with a directory ‘/var/www/html/sites/newsite/demo’ containing
the contents of the ‘source’ directory with everything copied properly.
Looking in the fileutils.rb source code, the comments state that this
is the correct behaviour.
Unfortunately, this is not what I want.
I tried using one of the examples from the fileutils.rb source:
FileUtils.cp_r( Dir.glob(source + "/*"), dest )
and end up with the following error:
/usr/local/lib/ruby/1.8/fileutils.rb:747: No such file or directory - /var/www/html/sites/newsite/cgi-bin' (Errno::ENOENT) from /usr/local/lib/ruby/1.8/fileutils.rb:732:in
each’
from /usr/local/lib/ruby/1.8/fileutils.rb:732:in
fu_each_src_dest0' from /usr/local/lib/ruby/1.8/fileutils.rb:724:in
fu_each_src_dest’
from /usr/local/lib/ruby/1.8/fileutils.rb:349:in `cp_r’
from /usr/local/sbin/newsite.rb:70
/usr/local/lib/ruby/1.8/fileutils.rb:747: st2 = File.stat(b)
The way I interpret this is that FileUtils.cp_r(), when it’s given a
list of files, doesn’t create and recurse into directories that it
finds along the way.
Can anyone tell me how to get FileUtils to do what I want i.e. copy the
contents of one directory to another directory, recursively?
Or, is there another way? I’m not clear on whether FileUtils is up to
date, etc. and just want to get the job done!
Thanks!
Steve