在 Ant 中执行复制时在日志中显示警报消息



我已经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>

您可以使用 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>

最新更新