Search code examples
ant

How to do recursive copy of files and directories using ant task


Ant has inbuilt Copy task to copy multiple files. I tried to define following target in build.xml file

 <target name="copyFile">
        <copy todir="../CHECK">
            <fileset dir=".">
                <patternset id="AllFiles">
                    <include name="*"/>
                </patternset>
        </fileset>
        </copy>
   </target>

It is copying files and directories. However content within directories is not copied, instead directories are copied as empty to destination "../CHECK". Does Ant copy task provides capability to do recursive copy of files and directories


Solution

  • I found the answer name pattern in include should be "**" instead of "*". It does recursive copy of all contents

      <target name="copyFile">
                <copy todir="../CHECK">
                    <fileset dir=".">
                        <patternset id="AllFiles">
                            <include name="**"/>
                        </patternset>
                </fileset>
                </copy>
           </target>