如何在不删除目标目录中的现有文件的情况下复制Ant中的目录?

时间:2012-01-09 14:27:33

标签: ant build copy build-process

我有以下文件结构:

  • FolderToBeCopied
    • folder1中
      • somefile1
      • somefile2

我将FolderToBeCopied复制到已包含文件的位置:

  • DestinationFolder
    • folder1中
      • anotherfile1
      • anotherfile2

我在Ant构建脚本中使用以下内容进行复制:

<copy overwrite="true" todir="DestinationFolder">
            <fileset dir="FolderToBeCopied" includes="**">
            </fileset>
        </copy>

但是,当我运行构建脚本时,它会将文件somefile1和somefile2复制到目标位置的folder1,但会删除folder1中已有的文件(即anotherfile1,anotherfile2)。有没有办法阻止它删除目标文件夹中已有的文件?

2 个答案:

答案 0 :(得分:1)

是:在构建脚本中找到delete元素,删除DestinationFolder并删除它。

copy doesn't deleteoverwrite仅表示“即使目标比来源旧也要复制”​​。

答案 1 :(得分:0)

为了防止删除目标文件夹中的现有文件,您可以进行备份,为文件名添加时间戳:

<project name="demoSO" basedir=".">

   <tstamp>
    <format property="touch.time" pattern="yyMMddHHmmssSSS"/>
  </tstamp>

  <target name="copyMyFiles">
    <copy todir="DestinationFolder" includeemptydirs="false">
      <fileset dir="FolderToBeCopied">
      </fileset>
      <mapper type="glob" from="*" to="*-${touch.time}"/>
    </copy>
  </target>

</project>