I have a groovy script which takes a 2 zip files, unzips them, then processes them.
The problem I have is when I go to unzip the zip files, each unzipped file produces a subfolder then the content of the unzip file not the content itself.
Example:
Currently this happens when I unzip
content-1232.zip -> /content-1232/content/<all content here>
What I want is
content-1232.zip -> /content-1232/<all_content>
or
Put into a new directory
content-1232.zip -> /new_directory/<all_content>
I tried this but to no avail:
Path basePath = Paths.get(output.getAbsolutePath())
Path srcPath = Paths.get(pdfContent.getAbsolutePath())
Path targetPath = basePath
Files.move(srcPath, targetPath.resolve(basePath.relativize(srcPath)))
Seems like a very simple thing to do but I'm not have any luck. How can I accomplish this in groovy? Any help will be appreciated
Edit:
static void main(String[] args) {
logger.info("Beginning unpacking of content...")
def output = new File("/Users/Haddad/Desktop/workspace/c")
def pdfContent = new File("/Users/Haddad/Desktop/workspace/c/pdf-content")
// Look for test1 and test2 production content zip file, ensure there's only 1 and unzip
List appZip = FileUtil.discoverFiles(output, true, "test1-production-content-.*\\.zip")
List compliZip = FileUtil.discoverFiles(output,true,"test2-production-content-.*\\.zip")
assert appZip.size() == 1, "Did not find expected number of test1 content zip, actual size is: " + appZip.size()
assert compliZip.size() == 1, "Did not find expected number of test2 content zip, actual size is " + appZip.size()
def outputAppZip = new File(output.getAbsolutePath()+"/"+appZip.get(0).getName()+"-intermediate");
def outputCompliZip = new File(output.getAbsolutePath()+"/"+compliZip.get(0).getName()+"-intermediate");
ZipUtil.unzipToDisk(appZip.get(0), outputAppZip )
ZipUtil.unzipToDisk(compliZip.get(0), outputCompliZip )
// move it to pdf content
List applicationContent = FileUtil.discoverDirectories(output, "one-production-content-.*-intermediate", true)
assert applicationContent.size() == 1, "Did not find expected number of test1 contents " + applicationContent.size()
def success = FileUtil.copy(applicationContent.get(0), pdfContent)
assert success, "Could not copy tt content"
// move pdf content
List complianceContent = FileUtil.discoverDirectories(output, "two-production-content-.*-intermediate", true)
assert complianceContent.size() == 1, "Did not find expected number of test2 contents " + complianceContent.size()
success = FileUtil.copy(complianceContent.get(0), pdfContent)
assert success, "Could not copy pdf content"
// rename to not be unsupported
List unsupportedDirs = FileUtil.discoverDirectories(pdfContent, "_unsupported_.*", true)
for (File file : unsupportedDirs) {
file.renameTo(new File(file.getParentFile(), file.getName().replace("_unsupported_", "")))
}
logger.info("Completed!")
}