ant脚本-比较文件夹差异
最近开始学习ant脚本,当然了,像我这么懒的人是不会主动学习的,都是被工作逼的啊。在学习的过程中真的遇到了好多问题啊,本来用一个文件记录了在执行过程中遇到的问题与解决方法,结果一不小心文件被误删了,无法恢复,真是可惜啦。
好吧这里来说一下ant脚本比较文件夹差异,为啥要说这个呢,是因为发现网上的资料比较少,我当时找了好久也没有找到现成可用的代码,有些代码还写错了,真的是误导人啊,经过自己摸索,终于成功了,现将代码与大家分享一下。
<project name="ant获取增量包" default="getPatch">
<!-- delta变量用来存放增量包路径 -->
<property name="delta" value="${basedir}\patch\"/>
<!-- source变量存放最新版本包路径 -->
<property name="source" value="${basedir}\source1"/>
<!-- target变量存放旧版本包路径 -->
<property name="target" value="${basedir}\ant\target1"/>
<target name="getPatch">
<copy todir="${delta}"
verbose="false"
failοnerrοr="false"
preservelastmodified="false"
includeemptydirs="false">
<fileset dir="${source}">
<!-- 找出 source 和 target 中的不同的文件 -->
<different targetdir="${target}" ignoreFileTimes="true"/>
<!-- 并且文件在 source 和 target 目录下同时存在 -->
<present present="both" targetdir="${target}" />
</fileset>
<fileset dir="${source}">
<!-- 找出 source 和 target 中的不同的文件 -->
<different targetdir="${target}" ignoreFileTimes="true"/>
<!-- 并且只存在 source 端目录下而在 target 中不存在的 -->
<present present="srconly" targetdir="${target}" />
</fileset>
</copy>
</target>
</project>
1、 .present selector
好吧这里来说一下ant脚本比较文件夹差异,为啥要说这个呢,是因为发现网上的资料比较少,我当时找了好久也没有找到现成可用的代码,有些代码还写错了,真的是误导人啊,经过自己摸索,终于成功了,现将代码与大家分享一下。
<project name="ant获取增量包" default="getPatch">
<!-- delta变量用来存放增量包路径 -->
<property name="delta" value="${basedir}\patch\"/>
<!-- source变量存放最新版本包路径 -->
<property name="source" value="${basedir}\source1"/>
<!-- target变量存放旧版本包路径 -->
<property name="target" value="${basedir}\ant\target1"/>
<target name="getPatch">
<copy todir="${delta}"
verbose="false"
failοnerrοr="false"
preservelastmodified="false"
includeemptydirs="false">
<fileset dir="${source}">
<!-- 找出 source 和 target 中的不同的文件 -->
<different targetdir="${target}" ignoreFileTimes="true"/>
<!-- 并且文件在 source 和 target 目录下同时存在 -->
<present present="both" targetdir="${target}" />
</fileset>
<fileset dir="${source}">
<!-- 找出 source 和 target 中的不同的文件 -->
<different targetdir="${target}" ignoreFileTimes="true"/>
<!-- 并且只存在 source 端目录下而在 target 中不存在的 -->
<present present="srconly" targetdir="${target}" />
</fileset>
</copy>
</target>
</project>
1、 .present selector
- 从FileSet的指定的目录中选择在present的targetdir指定的目录中不存在或者两个目录中都存在的文件
- present="srconly"代表只从FileSet目录中选取targetdir指定目录中不存在的文件
- present="both"代表从FileSet目录和targetdir目录中选择两个目录都存在的文件
- <fileset dir="${ant.1.5}/src/main" includes="**/*.java">
- <present present="srconly" targetdir="${ant.1.4.1}/src/main"/>
- </fileset>
- 从Ant1.5的src/main包中选择在ant1.4的src.main包中不存在的java源文件 2、.different selector
- 从两个目录中选择被认为不同的文件
- 属性ignoreFileTimes默认为true,表示忽略文件修改时间
- <fileset dir="${ant.1.5}" includes="**/*.java">
- <different targetdir="${ant.1.4.1}/src/main" ignoreFileTimes="false"/>
- </fileset>
- 比较Ant工具1.4和1.5版本的Java源文件,从中选择不相同的文件,选择过程不忽略文件的修改时间