Skip to content

Commit

Permalink
conditionally include separator, addresses issue more properly
Browse files Browse the repository at this point in the history
  • Loading branch information
JuicyDragon committed Feb 7, 2022
1 parent 9c33581 commit 06919b3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Java/src/main/java/com/nuix/superutilities/misc/ZipHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ public static void compressDirectoryToZipFile(String directory, String zipFile,
*/
@SuppressWarnings("deprecation")
private static void compressDirectoryToZipfile(String rootDir, String sourceDir, ZipOutputStream out) throws IOException, FileNotFoundException {
for (File file : new File(sourceDir).listFiles()) {
for (File file : new File(sourceDir).listFiles()) {
if (file.isDirectory()) {
compressDirectoryToZipfile(rootDir, sourceDir + File.separator + file.getName(), out);
} else {
ZipEntry entry = new ZipEntry(sourceDir.replace(rootDir, "") + File.separator + file.getName());
String dir = sourceDir.replace(rootDir, "");
ZipEntry entry;
if (!dir.trim().isEmpty()) {
entry = new ZipEntry(dir + File.separator + file.getName());
} else {
entry = new ZipEntry(file.getName());
}

out.putNextEntry(entry);
FileInputStream in = new FileInputStream(sourceDir + File.separator + file.getName());
IOUtils.copy(in, out);
Expand Down

0 comments on commit 06919b3

Please sign in to comment.