Zip File Extraction Utility

  • Share this:

Code introduction


This function takes a path to a zip file and a destination folder path, and then extracts the zip file to the destination folder. If the provided path is not a valid zip file, it will print a message.


Technology Stack : zipfile

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zipfile_extract(source_path, destination_folder):
    import zipfile
    if zipfile.is_zipfile(source_path):
        with zipfile.ZipFile(source_path, 'r') as zip_ref:
            zip_ref.extractall(destination_folder)
    else:
        print("The provided path is not a valid zip file.")                
              
Tags: