gpt4 book ai didi

Ant:压缩目录的内容,没有顶级目录本身

转载 作者:行者123 更新时间:2023-12-04 21:22:49 27 4
gpt4 key购买 nike

如何使用 Ant 创建包含某个根目录中的所有文件和嵌套目录的 zip,但从 zip 中排除顶级目录本身。

例如,假设我有这个文件结构:

/foo
splat.js
/bar
wheee.css

我希望 zip 包含 splat 和/bar 内的 wheee,但我 不要希望所有这些都包含在“foo”目录中。换句话说,将它解压到/honk 应该 不是 创建一个 foo 目录; splat 和 bar 应该在/honk 的根部结束。

我目前正在使用这个(删除了无关的细节):
<zip destfile="${zipfile}" basedir="" includes="${distRoot}/**/*.*" />

什么样的文件集选择可以替代“包含”规范来实现这一点?

最佳答案

它不是动态的,但使用 fullpath 属性允许您定义 zip 文件的路径结构。参见 Ant 文档:http://ant.apache.org/manual/Types/zipfileset.html

<zip destfile="YourZipName.zip">
<zipfileset fullpath="splat.js" dir="foo" includes="splat.js"/>
<zipfileset fullpath="bar/wheee.css" dir="foo/bar" includes="wheee.css"/>
</zip>

这可能会让你想要你想要的动态。它应该拉入 foo 目录中的所有内容,然后将其压缩。这只是一些额外的步骤。
<mkdir dir="DirToBeZipped"/>
<copy todir="DirToBeZipped">
<fileset dir="foo" includes="*"/>
</copy>
<zip destfile="YourZipName.zip" basedir="DirToBeZipped"/>

关于Ant:压缩目录的内容,没有顶级目录本身,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9117982/

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