File size: 1,169 Bytes
2d90d0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import zipfile
import os
def unzip_file(zip_file_path: str, destination_folder: str) -> None:
    """Unzips a ZIP file to the specified destination folder.

    Args:
        zip_file_path: The path to the ZIP file.
        destination_folder: The path to the folder where the contents should be extracted.
    """
    
    try:
        # Check if the ZIP file exists
        if not os.path.isfile(zip_file_path):
            raise FileNotFoundError(f"ZIP file not found: {zip_file_path}")

        # Check if the destination folder exists and create it if necessary
        os.makedirs(destination_folder, exist_ok=True)

        # Extract the ZIP file
        with zipfile.ZipFile(zip_file_path, 'r') as zip_ref:
            zip_ref.extractall(destination_folder)
        print(f"Successfully unzipped '{zip_file_path}' to '{destination_folder}'")
    
    except zipfile.BadZipFile:
        print(f"Error: '{zip_file_path}' is not a valid ZIP file.")
    except FileNotFoundError as e:
        print(e) # Print the error message for FileNotFoundError
    except Exception as e:  # Catch any other unexpected errors
        print(f"An unexpected error occurred: {e}")