Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ant-Zip解压父目录_Ant - Fatal编程技术网

Ant-Zip解压父目录

Ant-Zip解压父目录,ant,Ant,我有几个zip文件需要在Ant目标中解压缩。所有zip文件都位于同一目录中,并且具有相同的内部目录和文件结构 因此,我使用下面的代码片段解压目录中的所有zip文件,但每个zip文件在根目录中不包含父文件夹,因此每个后续zip文件都会解压并覆盖以前的文件 <unzip dest="C:/Program Files/Samsung/Samsung TV Apps SDK/Apps"> <fileset dir="."> <

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

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

<unzip dest="C:/Program Files/Samsung/Samsung TV Apps SDK/Apps">            
    <fileset dir=".">
        <include name="**/*.zip"/>
    </fileset>
</unzip>
然后,将每个文件的内容提取到:

1/
2/
3/

谢谢

一种解决方案可能是使用“for”和“propertyregex”任务来执行此操作:

<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
扩展名以用作目标目录名。

不带ant contrib:



是的,这就是我最终要做的。我希望不必使用ant contrib,但在本例中,这可能是最简单的方法。此解决方案仅在warFilePath正好引用1个文件时有效。OP询问如何提取几个文件。
<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>
<!-- Get the path of the war file. I know the file name pattern in this case -->
<path id="warFilePath">
    <fileset dir="./tomcat/webapps/">
        <include name="myApp-*.war"/>
    </fileset>
</path>

<property name="warFile" refid="warFilePath" />

<!-- Get file name without extension -->
<basename property="warFilename" file="${warFile}" suffix=".war" />

<!-- Create directory with the same name as the war file name -->
<mkdir dir="./tomcat/webapps/${warFilename}" />

<!-- unzip war file -->
<unwar dest="./tomcat/webapps/${warFilename}">
    <fileset dir="./tomcat/webapps/">
        <include name="${warFilename}.war"/>    
    </fileset>
</unwar>