ZipTree List Root Directory

Am trying to find a way to extract just the root directory name from a zip file. This is what I’m using right now which does work but the visit extracts all of the files/directories in the archive:

        def fileNames = []
        zipTree(configurations.jdkWindows.singleFile).visit{FileVisitDetails details -> fileNames << details.name}
        def rootDirectory = fileNames[0]

Is there a way to specify only to retrieve the top level directory name? or a way to specify the root directory name?

Thanks,
Ricky

Extracting the files from a zip file is a pretty standard requirement, which zipTree helps accomplish. You’re not going to find a specific Gradle shortcut to grab the root directory name without extracting it. You would need to write your own logic to scan through the contents of the zip for this case using the ZipFile classes in the JVM, or similar.

Thanks James! May take a look at writing my own logic as you suggested.