I need to process a zip archive which itself contains zip archives which all follow the same structure:
main.zip/
foo-1.txt
foo-1.zip/
...
tests/
...
bar-1.txt
bar-1.zip/
...
tests/
...
bar-2.txt
bar-2.zip/
...
tests/
...
foobar-1.txt
foobar-1.zip/
...
tests/
...
I want to extract the txt files and the tests directories into a structure like this:
foo/
1/
submission.txt
tests/
bar/
1/
submission.txt
tests/
2/
submission.txt
tests/
foobar/
1/
submission.txt
tests/
I managed to get the directory structure and the text files into the right place:
<target name="extract submissions">
<copy todir="${basedir}">
<zipfileset refid="submissions.zip"/>
<mapper type="regexp" from="(.*)-(.*)\.txt" to="\1/\2/\submission.txt"/>
</copy>
</target>
But now I am stuck how to access the tests directory inside the inner zips. I tried an intermediate step where I copied the inner zips into the place where the tests directories should end up. But how can I access the content of a zip archive without knowing its exact path?
I finally found a pure Ant solution:
The first target extracts the outer zip file and calls the second target on each extracted directory. This is achieved by a subant. The second target then unzips an inner zip file. Since it is applied in any subdirectory, all the inner zips are extracted.