My goal is to copy a set of files specified by a pattern to the target dir. The files in source directory can have subdirs.
I tried:
cp_r(Dir.glob('**/*.html'), @target_dir):
and
cp_r(FileList['**/*.html'], @target_dir):
but neither work.
it only works when I do something like:
cp_r(Dir['.'], @target_dir):
But I need to copy only *.html files not anything else.
I need what
cp --parents
Command does
Any advice using existing Ruby/Rake methods?
UPDATE Looks like thing which is easier to do with Ant, is not possible with Ruby/Rake stack - may be I would need to look into something else. I don't want to write custom code to make it work in Ruby. I just thought about Ruby/Rake as appropriate solution for that.
UPDATE 2 This is how I do it with Ant
<target name="buildeweb" description="Builds web site" depends="clean">
<mkdir dir="${build.dir.web}" />
<copy todir="${build.dir.web}" verbose="true">
<fileset dir="${source.dir.web}">
<include name="**/*.html" />
<include name="**/*.htm" />
</fileset>
</copy>
<chmod perm="a+x">
<fileset dir="${build.dir.web}">
<include name="**/*.html" />
<include name="**/*.htm" />
</fileset>
</chmod>
</target>
If you want pure Ruby, you can do this (with a little help from FileUtils in the standard library).
require 'fileutils'
Dir.glob('**/*.html').each do |file|
dir, filename = File.dirname(file), File.basename(file)
dest = File.join(@target_dir, dir)
FileUtils.mkdir_p(dest)
FileUtils.copy_file(file, File.join(dest,filename))
end
I haven't heard of cp --parents
, but if it does what you want then there is no shame in just using it from your Rakefile, like this:
system("cp --parents #{your} #{args}")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With