Create and Extract Zip Files

  • Share this:

Code introduction


Create a zipfile, add a specified file to the zipfile, and extract it to a specified directory.


Technology Stack : zipfile

Code Type : File operation

Code Difficulty : Intermediate


                
                    
def zipfile_create_extract(filename, mode='w'):
    import zipfile

    with zipfile.ZipFile(filename, mode) as z:
        z.write('example.txt', 'example.txt')
        z.extractall('extracted_files')                
              
Tags: