Alex Rivera | Logout

How to copy a directory using Ant

Asked 2009-11-06T04:35:40.660
112

I have used copydir to copy a directory tree but it is deprecated. My directory contains some sub-directories, and some of those contain files and others contain more sub-directories.

How can I copy the entire tree?

Edit
Report

2 Answers

132

Copy contents including the directory itself.

<copy todir="${dest.dir}" >  
    <fileset dir="${src.dir.parent}">  
        <include name="${src.dir}/**"/>
    </fileset>
</copy>

Note: ${src.dir} is relative to ${src.dir.parent}, and not a full path

answered 2011-12-14T17:22:24.857
26

You should only have to specify the directory (sans the includes property):

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

See the manual for more details and examples.

answered 2009-11-06T04:45:30.440

Your Answer