【问题标题】:Ant copy files by reading property fileAnt 通过读取属性文件复制文件
【发布时间】:2011-10-22 23:07:02
【问题描述】:

我有 2 组属性。一个是文件列表,另一个是目录列表。像这样

文件=file1,file2,file3,file4

destination.dir=dir1,dir2,dir3,dir4

这 2 个属性在 build.properties 中定义。

我想将file1复制到dir1,file2复制到dir2等等。

如何在 ant 中实现这一点?

谢谢

【问题讨论】:

    标签: file ant properties copy


    【解决方案1】:

    Ant 插件解决方案Flaka

    <project xmlns:fl="antlib:it.haefelinger.flaka">
    <!-- make standard ant tasks like copy understand EL expressions -->
    <fl:install-property-handler />
    
    <property name="files" value="/some/path/file1,/some/path/file2,/some/path/file3,/some/path/file4"/>
    <property name="destination.dir" value="/some/otherpath/dir1,/some/otherpath/dir2,/some/otherpath/dir3,/some/otherpath/dir4"/>
    
     <!-- iterate over the csv property destination.dir -->
     <fl:for var="dir" in="split('${destination.dir}', ',')">
      <!-- copy the first item from csv property ${files} -->
      <copy file="#{split('${files}',',')[0]}" todir="#{dir}" verbose="true"/>
      <!--
         afterwards delete this file item from csv property ${files}, means
         editing and overwriting ${files} for the next loop
      -->
        <fl:let>files ::= replace('${files}', '' , '#{split('${files}',',')[0]},?' )</fl:let>
     </fl:for>
    
    </project>
    

    或者在脚本任务中使用一些脚本语言,如 groovy、beanshell、(j)ruby、javascript ..

    【讨论】:

      猜你喜欢
      • 2016-09-08
      • 2017-07-20
      • 2015-11-25
      • 1970-01-01
      • 2013-01-13
      • 2021-10-04
      • 1970-01-01
      • 2023-04-04
      • 2019-12-09
      相关资源
      最近更新 更多