Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ant [17.11.2015 @ 08:10]
Christophe Frattino
ant [24.03.2017 @ 09:03] (current)
Christophe Frattino [Delete files and folders (incl. content)]
Line 1: Line 1:
 ====== Ant ====== ====== Ant ======
 +  * [[http://​ant.apache.org/​|http://​ant.apache.org/​]]
 ===== Ant methods ===== ===== Ant methods =====
 ==== Print a message ==== ==== Print a message ====
Line 20: Line 21:
 </​code>​ </​code>​
 ===== File manipulation ===== ===== File manipulation =====
-==== Copy file to folder ​ ====+==== Copy/move file to folder ​ ====
 <code xml> <code xml>
 <copy file="​file.txt"​ todir="​TargetDirectory\"​ /> <copy file="​file.txt"​ todir="​TargetDirectory\"​ />
 +<copy file="​file.txt"​ todir="​TargetDirectory\"​ overwrite="​true"​ />
 +<move file="​file.txt"​ todir="​TargetDirectory\"​ />
 </​code>​ </​code>​
-==== Copy folder to folder ​(incl. content) ​====+==== Copy/move folder ​content ​to folder ====
 <code xml> <code xml>
 <copy todir="​TargetDirectory\">​ <copy todir="​TargetDirectory\">​
    <​fileset dir="​SourceDirectory\"​ />    <​fileset dir="​SourceDirectory\"​ />
 +</​copy>​
 +<move todir="​TargetDirectory\">​
 +   <​fileset dir="​SourceDirectory\"​ />
 +</​move>​
 +</​code>​
 +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 xml>
 +<code file="​from.txt"​ tofile="​otherFolder\to.txt"​ />
 +<move file="​from.txt"​ tofile="​otherFolder\to.txt"​ />
 +</​code>​
 +==== Copy subset of folder content to folder (incl. content) ====
 +<code xml>
 +<copy todir="​TargetDirectory\">​
 +   <​fileset dir="​SourceDirectory\">​
 +      <include name="​*.zip"​ />
 +   </​fileset>​
 </​copy>​ </​copy>​
 </​code>​ </​code>​
Line 38: Line 63:
 <delete file="​file.txt"​ /> <delete file="​file.txt"​ />
 <delete dir="​folder\"​ /> <delete dir="​folder\"​ />
 +<​delete>​
 +   <​fileset dir="​folder\">​
 +      <include name="​whatever*.txt"​ />
 +      <include name="​hello*.docx"​ />
 +   </​fileset> ​  
 +</​delete>​
 </​code>​ </​code>​
 ==== Create a folder ==== ==== Create a folder ====
 <code xml> <code xml>
 <mkdir dir="​temp"​ /> <mkdir dir="​temp"​ />
 +</​code>​
 +==== Zip a folder ====
 +<code xml>
 +<zip basedir="​folder\"​ destfile="​archive.zip"​ />
 +</​code>​
 +===== System =====
 +==== Zip a folder and get zip "one folder up" ====
 +<code xml>
 +<zip destfile="​archive.zip">​
 +   <​mappedresources>​
 +      <fileset dir="​folder\"​ />
 +      <​cutdirsmapper dirs="​1"​ />
 +   </​mappedresources>​
 +</​zip>​
 </​code>​ </​code>​
 ===== System ===== ===== System =====
 ==== Run an executable ==== ==== Run an executable ====
 <code xml> <code xml>
-<exec executable="​c:​\path\to\executable.exe">​+<exec executable="​c:​\path\to\executable.exe" dir="​optionalWorkingDirectory\"​ output="​optionalWriteOutputToFile.txt">
    <​arg value="​first_parameter"​ />    <​arg value="​first_parameter"​ />
    ...    ...
 </​exec>​ </​exec>​
 </​code>​ </​code>​
Print/export