Ant Zip Extracted Parent Directory

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

Therefore, I use the following fragment to decompress all zip files in the directory, but each zip file does not contain the parent folder in the root, so each subsequent zip file is unpacked and overwrites the previous files.

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

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

So if zip files:

1.zip
2.zip
3.zip

then the contents of each of them will be extracted to:

1/
2/
3/

thank

+3
source share
2 answers

ant-contrib '' '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 .

+4

ant -contrib: fooobar.com/questions/1780026/...

<!-- 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>
-1

Source: https://habr.com/ru/post/1780025/


All Articles