在 Ant 中进行复制时在日志中显示警报消息 [英] Showing alert message in logs while doing copy in Ant

查看:38
本文介绍了在 Ant 中进行复制时在日志中显示警报消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 fromfolder=xxx 它有 one.txt
tofolder=yyy 是否有相同的文件 one.txt

I have fromfolder=xxx it has one.txt and
tofolder=yyy same file is there one.txt

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

While performing copy operation by using ant if it found same name of file is present then it will show alert message like files already present one.txt in log and should not overwrite the file.

 <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>

推荐答案

您可以使用 常规任务遍历文件:

You can use the groovy task to iterate thru the files:

  <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>

这篇关于在 Ant 中进行复制时在日志中显示警报消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆