Zip File Extraction Function

  • Share this:

Code introduction


This function is used to extract content from a zip file to a 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 FileNotFoundError("The specified file is not a valid zipfile.")                
              
Tags: