在日志中显示警告信息,而在ANT做副本 [英] Showing alert message in logs while doing copy in ANT

查看:118
本文介绍了在日志中显示警告信息,而在ANT做副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有fromfolder = XXX已one.txt
tofolder = YYY同一个文件有one.txt

同时通过蚂蚁进行复制操作


如果找到的文件的名称相同
present它就会出现像警报信息
文件已经present one.txt日志,不应该覆盖文件

任何人可以帮助我
我重视我的样本code

 <目标名称=copyPublicHtml描述=复制的public_html到输出目录>
     <触摸和GT;
     <文件集DIR =../ HTML/>
    < /触摸>       <副本todir =../ HTMLfailonerror =上的详细=上覆盖=false的>
            <文件集DIR =../ SRC>
       < /复制>
  < /目标与GT;


解决方案

您可以使用常规任务的迭代THRU文件:

 <目标名称=copyPublicHtml取决于=初始化描述=复制的public_html到输出目录>
    <组织codehaus.groovy.ant.Groovy的taskdef NAME =常规类名= classpathref =build.path/>    <文件集ID =srcFilesDIR =SRC/>    <常规>
      project.references.srcFiles.each {
        高清SRC =新的文件(it.toString())
        高清TRG =新的文件(HTML,src.name)        如果(trg.exists()){
          project.log文件已存在:$ {} TRG
        }        ant.copy(文件:它,todir:HTML,详细:真,改写:假)
      }
    < /常规>
  < /目标与GT;

i have fromfolder=xxx it has one.txt tofolder=yyy same file is there 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

can anybody help me i have attached my sample code

 <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天全站免登陆