Ant Zip 提取的父目录 [英] Ant Zip Extracted Parent Directory

查看:28
本文介绍了Ant Zip 提取的父目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个 zip 文件需要在 Ant 目标中解压缩.所有的 zip 文件都在同一个目录下,并且具有相同的内部目录和文件结构.

I have several zip files that I need to unzip within an Ant target. All the zip files are in the same directory, and have the same internal directory and file structure.

因此,我使用以下代码段来解压缩目录中的所有 zip 文件,但每个 zip 文件的根目录都不包含父文件夹,因此每个后续 zip 文件都被解压缩并覆盖之前的文件.

So I am using the following snippet to unzip all the zip files in the directory, but each zip file does not contain a parent folder at the root, so each successive zip file is unzipped and overwrites the previous files.

<unzip dest="C:/Program Files/Samsung/Samsung TV Apps SDK/Apps">            
    <fileset dir=".">
        <include name="**/*.zip"/>
    </fileset>
</unzip>

有没有更好的方法来解压一组文件,并根据 zip 文件名创建一个解压目录?

Is there a better way to unzip a group of files, and create a directory to unzip them to that is based on the zip file name?

所以,如果 zip 文件是:

So, if the zip files are:

1.zip
2.zip
3.zip

然后每个的内容将被提取到:

then the content of each will be extracted to:

1/
2/
3/

谢谢

推荐答案

一种解决方案可能是使用 ant-contrib 'for' 和 'propertyregex' 任务来做到这一点:

One solution might be to use the ant-contrib 'for' and 'propertyregex' tasks to do this:

<for param="my.zip">
  <fileset dir="." includes="**/*.zip" />
  <sequential>
    <propertyregex property="my.zip.dir"
              input="@{my.zip}"
              regexp="(.*)\..*"
              select="\1"
              override="yes" />
    <unzip src="@{my.zip}" dest="${my.zip.dir}" />
  </sequential>
</for>

'propertyregex' 从 zip 文件名中去除 .zip 扩展名以用作目标目录名.

The 'propertyregex' strips the .zip extension from the zip file name to use as the target directory name.

这篇关于Ant Zip 提取的父目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆