Ant methods

<echo>Hello world</echo>
<echo message="Hello world" />

Call a target

<antcall target="any_target">
   <param name="any_param" value="any_value" />

Include an external buildfile and call its targets

<include file="other_build.xml" as="any_id" />
<antcall target="any_id.external_target" />

File manipulation

Copy/move file to folder

<copy file="file.txt" todir="TargetDirectory\" />
<copy file="file.txt" todir="TargetDirectory\" overwrite="true" />
<move file="file.txt" todir="TargetDirectory\" />

Copy/move folder content to folder

<copy todir="TargetDirectory\">
   <fileset dir="SourceDirectory\" />
<move todir="TargetDirectory\">
   <fileset dir="SourceDirectory\" />

Notes :

  • To overwrite, add overwrite=“true” to the parent tag.
  • To flatten the folder, add flatten=“true” to the parent tag.
  • To get rid of the empty folders during the copy, add includeemptydirs=“false” to the parent tag.
  • The folder “SourceDirectory” won't be created in the target ! Only it's content will be copied/moved !
  • To ignore errors, add failonerror=“false” to the parent tag.

Copy/move/rename file to another file

<code file="from.txt" tofile="otherFolder\to.txt" />
<move file="from.txt" tofile="otherFolder\to.txt" />

Copy subset of folder content to folder (incl. content)

<copy todir="TargetDirectory\">
   <fileset dir="SourceDirectory\">
      <include name="*.zip" />

Write in a text file

<echo message="Hello world" file="hello_world.txt" />

Delete files and folders (incl. content)

<delete file="file.txt" />
<delete dir="folder\" />
   <fileset dir="folder\">
      <include name="whatever*.txt" />
      <include name="hello*.docx" />

Create a folder

<mkdir dir="temp" />

Zip a folder

<zip basedir="folder\" destfile="" />


Zip a folder and get zip "one folder up"

<zip destfile="">
      <fileset dir="folder\" />
      <cutdirsmapper dirs="1" />


Run an executable

<exec executable="c:\path\to\executable.exe" dir="optionalWorkingDirectory\" output="optionalWriteOutputToFile.txt">
   <arg value="first_parameter" />