0

I have a directory structure like this: Parent |->A |->B |->* and I need to zip it like so: Dest |->A.zip |->B.zip |->*.zip Where the * means that I don't know what are the names of the sub-folders.

How can I do this?

I'm working with a maven project but I don't mind using the antrun plugin

Tunaki
  • 132,869
  • 46
  • 340
  • 423
sagioto
  • 251
  • 1
  • 5
  • 16
  • Are À` and `B` modules of your parent `Parent`? What does the `*` mean in particular `you don't know the names of the sub-folders` ? Are these folder sub modules or what? – khmarbaise May 27 '14 at 05:49
  • There's no concept of modules in here just sub folders of in the file system. The set of subfolders is unknown. – sagioto May 27 '14 at 09:20

2 Answers2

2

Here is another solution that I like since it doesn't require antcontrib:

<target name="zipContentPackage">
    <basename property="dir.name" file="${file_name}"/>
    <echo message="Zipping folder: ${dir.name}"/>
    <zip destfile="${zip_dir}/${dir.name}.zip" basedir="${file_name}"/>
</target>

<target name="-wrapper-zipContentPackage">
    <antcall target="zipContentPackage" inheritAll="true">
        <param name="file_name" value="${basedir}" />
    </antcall>
</target>

<target name="packageContent">
    <delete dir="${zip_dir}"/>
    <mkdir dir="${zip_dir}"/>

    <subant genericantfile="${ant.file}" target="-zipContentPackage" inheritall="true">
        <dirset dir="${content_dir}" includes="*" />
    </subant>
</target>

Notes:

  1. I used sagioto's code to illustrate
  2. This isn't the most efficient solution
Community
  • 1
  • 1
srbs
  • 634
  • 9
  • 12
0

I ended up using foreach of antcontrib

<target name="init">
    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.compile.classpath"/>
</target>


<target name="packageContent" depends="init">
    <delete dir="${zip_dir}"/>
    <mkdir dir="${zip_dir}"/>
    <foreach target="zipContentPackage" param="file_name">
        <path>
            <dirset dir="${content_dir}" includes="*"/>
        </path>
    </foreach>
</target>

<target name="zipContentPackage">
    <basename property="dir.name" file="${file_name}"/>
    <echo message="Zipping folder: ${dir.name}"/>
    <zip destfile="${zip_dir}/${dir.name}.zip" basedir="${file_name}"/>
</target>
sagioto
  • 251
  • 1
  • 5
  • 16