Re: Moving batches of files with Rake



Gavin Kistner wrote:
I'm comparing Rake and NAnt for our pseudo-build process needs. I've
written the NAnt build file, and now I'm trying to port it (directly
at first) to Rake.

NAnt has a 'move' task for moving batches of files to a new directory.
By default, if you list specific files that don't exist, they are
ignored (not errored). Here's an example of the NAnt section I'm
trying to recreate:

<move todir="${path.intermediate}">
<fileset>
<include name="${dae}" />
<include name="${presentation_name}_org.bgf" />
</fileset>
</move>
<move todir="${path.data}">
<fileset basedir="${path.dae}">
<include name="${presentation_name}.bgf" />
<include name="${presentation_name}.nif" />
<include name="*.bvs" />
<include name="*.lua" />
</fileset>
</move>

Is there a built-in method for doing something like this (using
FileSet perhaps) that I'm not seeing in Rake? If not, does someone
else have a pre-built method that does this?

Use a file list to build up your list of files. Eg.

DAE_FILES = FileList[DAE, "#{PRESENTATION_NAME}_org.pgf"]

Then just use a mv command. Unfortunately, using mv with a file list
seems to require an explicit 'to_a' call. That shouldn't be the case
(I'll see if I can fix that in an update).

Example:

task :move_files do
mv DAE_FILES.to_a, PATH_INTERMEDIATE
end

If you don't want errors on non-existent files, you can filter them out:

task :move_files do
mv DAE_FILES.select { |fn| File.exist?(fn) }.to_a,
PATH_INTERMEDIATE
end

Wordy, but it works.

-- Jim Weirich


--
Posted via http://www.ruby-forum.com/.

.



Relevant Pages

  • Rake vs NAnt - a real-life example
    ... Is it a good idea to replace some or all of your Ant build with Rake? ... The story begins with a fairly normal, run of the mill, Nant build for a NET project, building a fairly normal, run of the mill, enterprise application. ... For example, if I say 'rake test' and nothing has changed within the ./sql directory since the last build, the step for recreating the database is skipped. ... * Custom tasks are very easy to write. ...
    (comp.lang.ruby)
  • Moving batches of files with Rake
    ... I'm comparing Rake and NAnt for our pseudo-build process needs. ... Is there a built-in method for doing something like this (using ... FileSet perhaps) that I'm not seeing in Rake? ...
    (comp.lang.ruby)