0

我有fromfolder=xxx它,one.txt并且有
tofolder=yyy相同的文件one.txt

在使用 ant 执行复制操作时,如果发现存在相同名称的文件,则会显示警告消息,如one.txt日志中已存在的文件,不应覆盖该文件。

 <target name="copyPublicHtml" description="Copy Public_html to output directory" >
     <touch>
     <fileset dir="../html"/>
    </touch>

       <copy todir="../html" failonerror="on" verbose="on" overwrite="false"> 
            <fileset dir="../src">           
       </copy>
  </target>
4

1 回答 1

0

您可以使用groovy 任务来遍历文件:

  <target name="copyPublicHtml" depends="init" description="Copy Public_html to output directory">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <fileset id="srcFiles" dir="src"/>

    <groovy>
      project.references.srcFiles.each {
        def src = new File(it.toString())
        def trg = new File("html", src.name)

        if (trg.exists()) {
          project.log "File already exists: ${trg}"
        }

        ant.copy(file:it, todir:"html", verbose:"true", overwrite:"false")
      }
    </groovy>
  </target>
于 2013-01-30T21:12:02.590 回答