如何使用ant将2个文件夹的不同文件复制到新位置

时间:2012-02-10 08:35:24

标签: ant copy

有两个文件夹A和B.我需要将A和B之间的不同文件复制到第三个文件夹C.我该怎么办?在ant中有一个不同的集合,但如何在副本中使用它?谢谢你的任何想法。

1 个答案:

答案 0 :(得分:0)

以下ANT脚本只会复制两个目录中不存在的文件:

<project name="copy" default="copy-files">

    <target name="copy-files">
        <copy todir="C" verbose="true" overwrite="true">
            <fileset dir="A">
                <present present="srconly" targetdir="B"/>
            </fileset>
            <fileset dir="B">
                <present present="srconly" targetdir="A"/>
            </fileset>
        </copy>
    </target>

</project>

测试设置:

$ tree
.
|-- A
|   |-- one
|   |-- shared
|   `-- two
|-- B
|   |-- four
|   |-- shared
|   `-- three
`-- build.xml

运行构建表明不会复制名为“shared”的文件:

$ ant
Buildfile: build.xml

copy-files:
     [copy] Copying 4 files to C
     [copy] Copying A/one to C/one
     [copy] Copying A/two to C/two
     [copy] Copying B/four to four
     [copy] Copying B/three to three

BUILD SUCCESSFUL
Total time: 0 seconds
相关问题