You can download this code by clicking the button below.
This code is now available for download.
This function is used to extract zip files to a specified directory. If the file is corrupted or does not exist, it will print out the corresponding error message.
Technology Stack : zipfile
Code Type : File processing
Code Difficulty : Intermediate
def zipfile_extract(zip_path, extract_to):
import zipfile
try:
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
zip_ref.extractall(extract_to)
except zipfile.BadZipFile:
print("The file is not a zip file or it is corrupted")
except FileNotFoundError:
print("The file was not found")