Ant

Ant methods

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

Call a target

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

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\" />
</copy>
<move todir="TargetDirectory\">
   <fileset dir="SourceDirectory\" />
</move>

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" />
   </fileset>
</copy>

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\" />
<delete>
   <fileset dir="folder\">
      <include name="whatever*.txt" />
      <include name="hello*.docx" />
   </fileset>   
</delete>

Create a folder

<mkdir dir="temp" />

Zip a folder

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

System

Zip a folder and get zip "one folder up"

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

System

Run an executable

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