# Tip for Unzipping Files and Handling Exceptions

**URL:** <https://forum.katalon.com/t/tip-for-unzipping-files-and-handling-exceptions/137611>\
**Category:** Tips and Tricks\
**Tags:** unzip-files\
**Created:** [July 17, 2024, 5:07pm UTC](https://forum.katalon.com/t/tip-for-unzipping-files-and-handling-exceptions/137611 "2024-07-17T17:07:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dave\_Evers](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/dave_evers/32/435_2.png) [@Dave\_Evers](https://forum.katalon.com/u/Dave_Evers)\
**Post date:** [July 17, 2024, 5:07pm UTC](https://forum.katalon.com/t/tip-for-unzipping-files-and-handling-exceptions/137611/1 "2024-07-17T17:07:16Z")

</div>

The following test case can be used for unzipping downloaded zip files.  
Copy and paste the following to any new test case, (edit for your requirements).

```auto
import com.kms.katalon.core.util.internal.ZipUtil

//Assumes there is an example.zip file in the user's download folder

// Concatenate the user's home directory with "/Downloads" to create a string representing the downloads folder path.
String downloadsFolder = System.getProperty("user.home") + "/Downloads";

// Create a new file object representing a zip file in a specified folder.
// You could use a GlobalVariable here ...
def zipFileName = 'example.zip'
File zipFile = new File(downloadsFolder + "/" + zipFileName);

// Create a new file object with the path specified by combining the downloads folder and "/unzipped".
// You could use a GlobalVariable here ...
def destDirectory = 'unzipped'
File destDir = new File(downloadsFolder + "/" + destDirectory);

/*
 * Unzip a file and handle any exceptions that may occur.
 * 1. Attempt to extract the zip file to the specified destination directory.
 * 2. If successful, print a success message.
 * 3. If an exception occurs, catch it and print an error message with the exception message.
*/

try {
	ZipUtil.extract(zipFile, destDir);
	println("File unzipped successfully");
} catch (Exception e) {
	println("Error unzipping the file: " + e.getMessage());
}

```

---

<div class="post-metadata">

**Author:** ![albert.vu](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/albert.vu/32/20595_2.png) [@albert.vu](https://forum.katalon.com/u/albert.vu)\
**Post date:** [August 16, 2024, 8:00am UTC](https://forum.katalon.com/t/tip-for-unzipping-files-and-handling-exceptions/137611/3 "2024-08-16T08:00:22Z")

</div>

Thank you @Dave_Evers for sharing this tip with us.

Hi em @Elly_Tran, can we make sure to promote Dave’s topic on our social media as well? Thanks!
