Pass
Pass

Reputation: 1501

Append text to multiple files in a directory using Ant

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?

Upvotes: 2

Views: 1574

Answers (1)

martin clayton
martin clayton

Reputation: 78105

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.

Upvotes: 4

Related Questions