Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Moving batches of files with Rake

Reply
Thread Tools

Moving batches of files with Rake

 
 
Phrogz
Guest
Posts: n/a
 
      03-30-2007
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?

 
Reply With Quote
 
 
 
 
Jim Weirich
Guest
Posts: n/a
 
      03-31-2007
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/.

 
Reply With Quote
 
 
 
 
Jim Weirich
Guest
Posts: n/a
 
      04-01-2007
Jim Weirich wrote:
[...]
> (I'll see if I can fix that in an update).\


I just created a beta version of Rake that supports this. You can now
say:

task :move_files do
mv DAE_FILES.existing, PATH_INTERMEDIATE
end

FileLists now support an 'existing' method which returns a filelist
containing on ly existing file names. (There is also an existing!
method that does the same thing to the existing file list). Also,
FileLists can now be passed directly to FileUtils methods just like
arrays.

If you want to try the beta version, do:

gem install rake --source http://onestepback.org/betagems

-- Jim Weirich

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple rake build files? large rake files thufir Ruby 3 04-12-2008 07:28 AM
Free Moving Estimate, Local Movers, Long Distance Moving, PackingSupplies, Storage Rental, Home Moving, Apartment Moving, Office Moving,Commercial Moving linkswanted ASP .Net 0 01-06-2008 04:45 AM
Scanner for large batches of Slides Toby Digital Photography 6 09-08-2007 08:36 AM
Rake and rake aborted! Rake aborted! undefined method `gem' for main:Object peppermonkey Ruby 1 02-10-2007 04:43 AM
Full-size DVD cases in batches of 20 (price check) Bruce P. Burrell DVD Video 5 01-24-2006 01:56 AM



Advertisments