Unzip Functionality

  • Share this:

Code introduction


This function is used to unzip a zip file, extracting the contents to the specified directory.


Technology Stack : zipfile

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zipfile_extract(file_path, extract_to_dir):
    import zipfile
    if zipfile.is_zipfile(file_path):
        with zipfile.ZipFile(file_path, 'r') as zip_ref:
            zip_ref.extractall(extract_to_dir)
    else:
        raise ValueError("The provided file is not a zip file.")                
              
Tags: