ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
Subject RE: Open and read file with ant and then copy
Date Mon, 10 Sep 2007 10:48:36 GMT

Hi,

-----Original Message-----
From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de] 
Sent: Monday, September 10, 2007 11:53 AM
To: user@ant.apache.org
Subject: AW: Open and read file with ant and then copy

/*
Just an idea and not tested. Use '=' for separating source from target
name. Used AntContrib.

copy.txt
--------
/a/b/c.xml=/d/e/f.xml
...



<loadfile property="allfiles" file="copy.txt"/>
<ac:for list="${allfiles}" param="line">
    <sequential>
        <ac:propertyregex property="from" input="@{file}"
regexp="(.*)=(.*)" select="\1" override="true"/>                   
        <ac:propertyregex property="to"   input="@{file}"
regexp="(.*)=(.*)" select="\2" override="true"/>
        <copy file="${from}" tofile="${to}"/>
    </>
</>
*/

Or another approach with <script> and JRuby

the given inputfile (1 - n lines) =

c:/test/inst/mm/connection.xml Y:/test/proj/rtu/connection.xml
c:/bla/foo/bar/foo.xml Y:/test/proj/rtu/foobar/foo.xml

the antscript =

<target name="depends">
<script language="ruby">
<![CDATA[
      
require 'fileutils'
     
File.open('C:\WKS\Eclipse322\test\copytest.txt', "r").each do |line|
  FileUtils.mkdir_p(File.dirname(line.split(' ')[1]),:verbose=>true)
  FileUtils.cp(line.split(' ')[0],line.split(' ')[1],:verbose=>true)
end
 ]]>
</script>
</target>

the output =

Buildfile: C:\WKS\Eclipse322\test\jruby_copy.xml
depends:
   [script] mkdir -p Y:/test/proj/rtu
   [script] cp c:/test/inst/mm/connection.xml
Y:/test/proj/rtu/connection.xml
   [script] mkdir -p Y:/test/proj/rtu/foobar
   [script] cp c:/bla/foo/bar/foo.xml Y:/test/proj/rtu/foobar/foo.xml
main:
BUILD SUCCESSFUL
Total time: 2 seconds


Regards, Gilbert

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message