# How to iterate filenames inside zipfile/warfile without creating /tmp/expandedArchives

**URL:** <https://discuss.gradle.org/t/how-to-iterate-filenames-inside-zipfile-warfile-without-creating-tmp-expandedarchives/25727>\
**Category:** Help/Discuss\
**Created:** [February 4, 2018, 7:25am UTC](https://discuss.gradle.org/t/how-to-iterate-filenames-inside-zipfile-warfile-without-creating-tmp-expandedarchives/25727 "2018-02-04T07:25:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![roonaan](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/roonaan/32/6587_2.png) [@roonaan](https://discuss.gradle.org/u/roonaan)\
**Post date:** [February 4, 2018, 7:25am UTC](https://discuss.gradle.org/t/how-to-iterate-filenames-inside-zipfile-warfile-without-creating-tmp-expandedarchives/25727/1 "2018-02-04T07:25:33Z")

</div>

Hi,

We have a multimodule project in which we implemented some safeguards by creating a verifyWar target to check the generated warfile. This check runs for all the projects with apply our `war.gradle`

[war.gradle]

```
/**
 * generic war configuration used by all modules which build wars
 *
 * add to your project using:
 * apply from: "$rootProject.projectDir/war.gradle"
 */

apply plugin: 'war'

/* ... deleted irrelevant task definitions ... */

task verifyWar {
    def destFile = file("$buildDir/verifyWar.txt")
    dependsOn war
    inputs.file war.archivePath
    outputs.file destFile
    doLast {
        zipTree(war.archivePath).each { file ->
            assert ("some-forbidden.jar" != file.name)
            assert ("some-forbidden-resource.xml" != file.name)
        }
        ant.echo(file: destFile, message:"verified at " + new Date())
    }
}
war.finalizedBy verifyWar

```

What happens however is that every time `verifyWar` is run a `.build/tmp/expandedArchives/myproject.war_{hash}` is created.

Gradle doesn’t clean it up afterwards, so if a developer doesn’t run clean often enough the new war is unpacked and the expandedArchives directory grows with each deploy. Which for an active project can be 8~15 times a day.

A few questions:

- Is there a flag on a zipFileTree that either make it clean up afterwards, or not expand at all?
- Is there another way maybe to just iterate the filenames, not using ZipFileTree whatsoever?

I’m not sure if I can aggressively delete the expandedArchives directory as a whole as I also see dependencies from the `war` task such as `from {zipFileTree (configurations.staticWebContent.archiveName}` and others being expanded there. Basically whenever we use zipFileTree.

---

<div class="post-metadata">

**Author:** ![jjustinic](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/jjustinic/32/9005_2.png) [@jjustinic](https://discuss.gradle.org/u/jjustinic)\
**Post date:** [February 5, 2018, 7:01am UTC](https://discuss.gradle.org/t/how-to-iterate-filenames-inside-zipfile-warfile-without-creating-tmp-expandedarchives/25727/2 "2018-02-05T07:01:55Z")

</div>

> [@roonaan](#):
>
> Is there another way maybe to just iterate the filenames, not using ZipFileTree whatsoever

You can use `java.util.zip.ZipFile` for this purpose, but the name of each `ZipEntry` will be the full path, so you would need to handle that. Alternatively, there’s also `war.eachFile { }` which could be used to check all files going into the war as they’re written instead of after the fact.
