簡體   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