How to rename a new directory created as result of unzip?

Am unzipping a tomcat distribution into the buildDir which results in a new directory being created (apache-tomcat-8.0.32) that contains the contents of the zip file. Need to rename this newly created directory from the tomcat specific directory name to a generic name (tomcat-prep) for subsequent processing.

So far we’ve only been able to achieve this with the following task:

task unzipTomcat() {
  doLast {
    copy {
      from(zipTree("$tomcatSourceDir/apache-tomcat-8.0.32-windows-x64.zip"))
      into buildDir
    }
    copy {
      from("$buildDir/apache-tomcat-8.0.32")
      into("$buildDir/tomcat-prep")
    }
    delete "$buildDir/apache-tomcat-8.0.32"
  } 
}

So instead of copying the source directory to the target directory and then deleting the source directory, is there any way to simply just rename the source directory (apache-tomcat-8.0.32) to the target directory (tomcat-prep)???

I believe you could use eachFile to modify the path similar to the way it was described in this post. It doesn’t necessarily make your logic more readable or maintainable - rather more complex.