How to use Ant to copy a folder?

I am trying to copy a directory using an Ant task copy.

I am new to Ant; my current solution is:

<copy todir="${release_dir}/lib">
   <fileset dir="${libpath}" />
</copy>

I am wondering if there is a better and shorter way to do the same?

+5
source share
4 answers

First of all, these are examples from the Ant documentation:

Copy directory to another directory

<copy todir="../new/dir">
  <fileset dir="src_dir"/>   
</copy>

Copy the set of files to the directory

<copy todir="../dest/dir">
  <fileset dir="src_dir">
    <exclude name="**/*.java"/>
  </fileset>
</copy>

<copy todir="../dest/dir">
  <fileset dir="src_dir" excludes="**/*.java"/>   
</copy>

Copy the set of files to the directory by adding .bak to the file name on the fly

<copy todir="../backup/dir">
  <fileset dir="src_dir"/>
  <globmapper from="*" to="*.bak"/>   
</copy>

Secondly, here is the whole documentation about the copy task.

+14
source

Just because the documents were not very clear to me, and because the time spent can serve others:

, " (dir1) (dest)":

<copy todir="../new/dest">
  <fileset dir="src/dir1"/>   
</copy>

"copy dir1 dest", " dir1 dest".

( , Ant, " " , todir .)

dir1 dest, ( ), , DirSet , )

<copy todir="../new/dest/dir1">
  <fileset dir="src/dir1"/>   
</copy>

<copy todir="../new/dest">
  <fileset dir="src" includes="dir1/**"/>
</copy>

. .

+4

:

<copy todir="directory/to/copy/to">
    <fileset dir="directory/to/copy/from"/>
</copy>

ant - : Ant Manual, :

+1

From http://ant.apache.org/manual/Tasks/copy.html :

<copy todir="../new/dir">
  <fileset dir="src_dir"/>
</copy>
+1
source

All Articles