2

I need to use ant to append some text to multiple files in a directory. I know I can use the echo command but how can I apply it to multiple files selected by a wildcard?

Pass
  • 1,501
  • 4
  • 21
  • 39

1 Answers1

4

You could do this by means of the Ant replaceregexp task. For example this will append to all the .txt files in the specified directory:

<replaceregexp match="$" replace="your text here" flags="s">
    <fileset dir="my_dir" includes="*.txt" />
</replaceregexp>

The flags and match attrributes in this case configure the task to append only to the end of the file.

You man need to make use of the ${line.separator} property in your append text if it is multiline.

martin clayton
  • 76,436
  • 32
  • 213
  • 198