问题
I have fromfolder=xxx
it has one.txt
andtofolder=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.
<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>
回答1:
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>
来源:https://stackoverflow.com/questions/14586610/showing-alert-message-in-logs-while-doing-copy-in-ant