M.Hussaini
M.Hussaini

Reputation: 135

Copy Multiple Files and Directories with ANT

I have an Ant Script, using the ANT LIBRARY how can i copy multiple files/folders to multiple directories. I use a properties file which contains

FileToCopy = DestinationFolder
FolderToCopy = FolderDestination

Upvotes: 4

Views: 13653

Answers (2)

bartgeier
bartgeier

Reputation: 271

Some additional information to sergiofbsilvas answer, because I was searching for such an example.

One can also specify multiple filesets in a single copy task.

Example:

<copy todir="${temp.dir}">
  <fileset dir="${classes.dir}"/>
  <fileset dir="${basedir}">
    <include name="log4j.xml"/>
    <include name="config.properties"/>
    <include name="kfatransfer.bat"/>
  </fileset>
</copy>

Tested with ant 1.10.6 on Windows.

Upvotes: 3

sergiofbsilva
sergiofbsilva

Reputation: 1606

Copy a single file

<copy file="myfile.txt" tofile="mycopy.txt"/>

Copy a single file to a directory

<copy file="myfile.txt" todir="../some/other/dir"/>

Copy a directory to another directory

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

Copy a set of files to a 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>

examples from copy ant task

Upvotes: 12

Related Questions