使用< copy>执行类似的操作是没有问题的.具有< present>的文件集元素,但解压缩似乎并不适用于我:
<unzip src="${cur.srcdir.live}" dest="${cur.srcdir.archive-files.dir}" overwrite="true"> <fileset dir="."> <present present="both" targetdir="${cur.srcdir}" /> <type type="file" /> </fileset> <globmapper from="*" to="*.${backup.suffix}" /> </unzip>
以前有人做过这样的事吗?这是Ant 1.8.0.谢谢!
我能够通过“伪造”< present>来解决我的问题.可以在< copy>中使用的选择器.这是如何做:首先,我使用pathconvert创建文件夹中的文件列表:
<pathconvert property="extract.list" pathsep="
"> <path> <fileset dir="${extract.src.dir}" includes="${extract.src.dir.relpath}"> <type type="file" /> </fileset> </path> <map from="${extract.src.dir}\" to="" /> </pathconvert>
注意地图的用户要使列表是相对路径而不是绝对路径.另外,分隔符是换行符.
然后将此列表写入文件:
<echo file="${props.tmp.file}" message="~~~~noop~~~~
${extract.list}" append="false" />
我把那个“nooop”条目放在那里,这样文件总是至少有一行.这很重要,因为我们将下一步用作包含文件.如果includesfile为空,则Ant将其解释为“允许任何内容”…但我们希望确保空列表不会从zip中提取任何内容.
最后一步是使用我们上面的临时文件从zip中提取作为包含文件. globmapper在提取时将文件重命名为适当的备份名称:
<unzip src="${extract.archive}" dest="${extract.dest.dir}" overwrite="true"> <patternset> <includesfile name="${props.tmp.file}" /> </patternset> <globmapper from="*" to="*.${backup.suffix}" /> </unzip>
精彩评论