How to copy a directory using Ant

前端 未结 11 1147
挽巷
挽巷 2020-12-13 08:49

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 contai

相关标签:
11条回答
  • 2020-12-13 09:05

    I'm adding a more generic pattern to copy all subfolders.

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

    See Patterns for details.

    0 讨论(0)
  • 2020-12-13 09:07

    A fine point: ant will only copy the sub-directories if the source files are newer than the destination files. [1] In my case, the sub-dirs were not being copied (I am using verbose="true"), since there were no changes and they were already in the destination. You can use "overwrite" to force it, or touch some of the files in your source sub-dirs.

    0 讨论(0)
  • 2020-12-13 09:13

    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

    0 讨论(0)
  • 2020-12-13 09:14

    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.

    0 讨论(0)
  • 2020-12-13 09:16

    From the example here, you can write a simple Ant file using copy task.

    <project name="MyProject" default="copy" basedir=".">
        <target name="copy">
            <copy todir="./new/dir">
               <fileset dir="src_dir"/>
            </copy>
        </target>
    </project>

    This should copy everything inside src_dir (excluding it) to new/dir.

    0 讨论(0)
提交回复
热议问题