Moving batches of files with Rake

Discussion in 'Ruby' started by Phrogz, Mar 30, 2007.

  1. Phrogz

    Phrogz Guest

    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?
    Phrogz, Mar 30, 2007
    #1
    1. Advertising

  2. Phrogz

    Jim Weirich Guest

    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/.
    Jim Weirich, Mar 31, 2007
    #2
    1. Advertising

  3. Phrogz

    Jim Weirich Guest

    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/.
    Jim Weirich, Apr 1, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. graham

    looping in batches

    graham, Mar 24, 2011, in forum: C++
    Replies:
    5
    Views:
    275
    Michael Doubez
    Mar 25, 2011
  2. Joe Van Dyk
    Replies:
    2
    Views:
    102
    Damphyr
    Jan 31, 2006
  3. peppermonkey
    Replies:
    1
    Views:
    243
    Gregory Brown
    Feb 10, 2007
  4. Replies:
    3
    Views:
    128
    Eivind Eklund
    Nov 27, 2007
  5. thufir
    Replies:
    3
    Views:
    218
    Thufir
    Apr 12, 2008
Loading...

Share This Page