重新定位动态文件夹的内容
我有一个 zip 文件,其中有一个基本文件夹,其中包含其他内容。在解压缩之前,我并不总是知道该基本文件夹将被称为什么。
我想移动该基本文件夹,并同时在 ant 中重命名它 - 但似乎不知道如何操作。我已经编写了代码将 zip 文件的内容提取到 ${local.sdk.dir}/temp/
但从这里我无法弄清楚如何重命名/移动提取的文件
<move todir="${local.sdk.dir}/${remote.sdk.file.name}">
<fileset dir="${local.sdk.dir}/temp/<WHAT_DO_I_PUT_HERE?>"></fileset>
</move>
夹尝试
<move todir="${local.sdk.dir}/${remote.sdk.file.name}" includeEmptyDirs="yes" verbose="true">
<fileset dir="${local.sdk.dir}/temp/" >
<include name="**/*" />
</fileset>
</move>
并玩过这个,但我能在不抛出错误的情况下得到的最接近的是复制临时目录的内容,而不是临时目录中的基本文件夹。
I have a zip file which has one base folder inside it with other content inside that. I don't always know what that base folder is going to be called until I unzip it.
I'd like to move that base folder, and rename it at the same time, in ant - but can't seem to find out how. I've written code to extract the contents of the zip file to ${local.sdk.dir}/temp/
but from here i can't work out how to rename/move the extracted folder
<move todir="${local.sdk.dir}/${remote.sdk.file.name}">
<fileset dir="${local.sdk.dir}/temp/<WHAT_DO_I_PUT_HERE?>"></fileset>
</move>
also tried
<move todir="${local.sdk.dir}/${remote.sdk.file.name}" includeEmptyDirs="yes" verbose="true">
<fileset dir="${local.sdk.dir}/temp/" >
<include name="**/*" />
</fileset>
</move>
and played about with this, but closest I can get without ant throwing an error is to copy the contents of the temp dir, not the base folder within temp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以一步完成所有这一切 - 从 zip 文件中复制并在复制时更改目录名称来重命名文件。
copy
任务 接受嵌套的资源集合,因此您可以使用zipfileset
指定直接从 zip 文件复制的文件。为了在复制文件时重命名文件,您可以使用 映射器,
copy
任务也将其作为嵌套元素。在这种情况下,cutsdirmapper
看起来像是完成这项工作的工具。因此,如果我已经理解您想要正确执行的操作,那么类似这样的操作应该有效:
cutdirsmapper
仅在 Ant 1.8.2 及以上版本中可用,因此如果您使用的是早期版本,您可以尝试regexpmapper
:You can do all this in one step - copy from the zip file and rename the files changing the dir name as you copy. The
copy
task accepts a nested resource collection, so you can use azipfileset
to specify the files to copy directly from the zip file.In order to rename the files as they are copied, you can use a mapper, which the
copy
task also takes as a nested element. In this case, acutsdirmapper
looks like the tool for the job.So, if I've understood what you want to do correctly, something like this should work:
cutdirsmapper
is only available in Ant 1.8.2 onward, so if you're using an earlier version, you could try aregexpmapper
:类似于这个问题
Similar to this question