Ant复制目录(如果在目录中找到文件)
我一直在使用simple copy从目录中获取特定文件:Ant复制目录(如果在目录中找到文件),ant,Ant,我一直在使用simple copy从目录中获取特定文件: <copy todir="target/failures"> <fileset dir="target/reports" includes="**/*FAILED.txt"/> </copy> 因此,如果在folder1中发现故障,我希望将整个内容复制到failures,然后继续浏览其余文件夹。看起来应该很简单,但我似乎找不到一个内置任务来完成这项任务,有什么想法吗?使用a来决定是否执行复制目
<copy todir="target/failures">
<fileset dir="target/reports" includes="**/*FAILED.txt"/>
</copy>
因此,如果在folder1中发现故障,我希望将整个内容复制到failures,然后继续浏览其余文件夹。看起来应该很简单,但我似乎找不到一个内置任务来完成这项任务,有什么想法吗?使用a来决定是否执行复制目标
<project name="demo" default="copy">
<fileset id="failures" dir="target/reports" includes="**/*FAILED.txt"/>
<condition property="failures.found">
<resourcecount refid="failures" when="greater" count="0" />
</condition>
<target name="copy" if="failures.found">
<copy todir="target/failures" overwrite="true">
<fileset id="failures" dir="target/reports"/>
</copy>
</target>
</project>
更新
更具能力和灵活性的解决方案使用:
project.references.failures.each{
def failFile=新文件(it.toString())
def failFolder=新文件(failFile.parent)
复制(todir:“target/failures/${failFolder.name}”,覆盖:true){
文件集(目录:failFolder)
}
}
这将复制所有内容,我已在问题中为我的结构添加了信息。给了我一个开始的地方,考虑编写一些代码在现有的实用程序中处理它…@SteveMiskiewicz我已经用一个嵌入式groovy脚本更新了我的答案
<project name="demo" default="copy">
<fileset id="failures" dir="target/reports" includes="**/*FAILED.txt"/>
<condition property="failures.found">
<resourcecount refid="failures" when="greater" count="0" />
</condition>
<target name="copy" if="failures.found">
<copy todir="target/failures" overwrite="true">
<fileset id="failures" dir="target/reports"/>
</copy>
</target>
</project>
<project name="demo" default="copy">
<path id="build.path">
<pathelement location="/path/to/task/jars/groovy-all-2.1.1.jar"/>
</path>
<target name="copy">
<taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
<fileset id="failures" dir="target/reports" includes="**/*FAILED.txt"/>
<groovy>
project.references.failures.each {
def failFile = new File(it.toString())
def failFolder = new File(failFile.parent)
ant.copy(todir:"target/failures/${failFolder.name}", overwrite:true) {
fileset(dir:failFolder)
}
}
</groovy>
</target>
</project>