gpt4 book ai didi

apache - 如何通过 Apache Ant 任务获取 ZIP 文件列表?

转载 作者:行者123 更新时间:2023-12-04 16:47:33 25 4
gpt4 key购买 nike

我需要使用 Apache Ant 任务获取 ZIP 文件中的文件名列表,而无需先将其解压缩。它还应该独立于操作系统,例如:如果 My.zip 包含:

dir1/path/to/file1.html
dir1/path/to/file2.jpg
dir1/another/path/file3.txt
dir2/some/path/to/file4.png
dir2/file5.doc

Ant 任务应返回上面的列表以及相对路径 + 文件名。

最佳答案

使用 zipfileset 的解决方案和 pathconvert , 包裹在 macrodef重用:

<project>

<macrodef name="listzipcontents">
<attribute name="file"/>
<attribute name="outputproperty"/>

<sequential>
<zipfileset src="@{file}" id="content"/>
<pathconvert property="@{outputproperty}" pathsep="${line.separator}">
<zipfileset refid="content"/>
<map from="@{file}:" to=""/>
</pathconvert>
</sequential>
</macrodef>

<listzipcontents file="path/to/whatever.zip|war|jar|ear" outputproperty="foobar"/>

<echo>$${foobar} => ${foobar}</echo>

</project>

优点:您可以使用所有文件集属性,例如include/exclude 如果您需要过滤 zipfilecontents - 只需使用附加属性扩展 macrodef,zipfileset 还支持其他文件,如 jar、war、ear。

关于apache - 如何通过 Apache Ant 任务获取 ZIP 文件列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37549133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com