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}")