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