繁体   English   中英

通过读取属性文件复制文件

[英]Ant copy files by reading property file

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

文件=文件1,文件2,文件3,文件4

destination.dir = DIR1,DIR2,DIR3,dir4

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

我想将file1复制到dir1,file2复制到dir2,依此类推。

如何在蚂蚁身上实现?

谢谢

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 ..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM