Zip File Extraction Utility

  • Share this:

Code introduction


This function is used to unzip a zip file to a specified directory.


Technology Stack : zipfile

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zipfile_extract(source, destination):
    import zipfile
    try:
        with zipfile.ZipFile(source, 'r') as zip_ref:
            zip_ref.extractall(destination)
    except FileNotFoundError:
        print("The file was not found.")
    except zipfile.BadZipFile:
        print("The file is not a zip file or it is corrupted.")                
              
Tags: