开发者

How to iterate over the file content using Ant script?

I need to read data from a file and do some further processing on that.

Actually I need to zip only those files which are modified. So prepared a tracksheet.txt which contains the list of all开发者_开发问答 modified files in source code.

Read each file from the tracksheet.txt file, fetch it from svn and zip it.


You could load the contents of the file using Ant's loadfile task. For example, assuming each entry is on a separate line, it would look something like this:

<loadfile
  property="changed.files"
  srcFile="tracksheet.txt">
  <filterchain>
    <striplinebreaks/>
  </filterchain>
</loadfile>

Then you can use Ant-Contrib's for or foreach task to loop over all the values in the property. For example:

<for list="${changed.files}" param="changedFile">
  <sequential>
    <echo>TODO fetch the file @{changedFile} from SVN</echo>
    <echo>TODO zip the file @{changedFile}</echo>
  </sequential>
</for>

Note that Ant-Contrib is not part of the standard install. You need a separate jar. Installation/usage instructions are on the website: http://ant-contrib.sourceforge.net


Similar to Chris his answer:

<loadfile property="changed.files" srcFile="tracksheet.txt"/>

<for list="${changed.files}" param="changedFile" delimiter="${line.separator}">
  <sequential>
    <echo>@{changedFile}</echo>
  </sequential>
</for>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜