Create ZIP File from Path

  • Share this:

Code introduction


This function compresses a file at a specified path into a zip format and saves it to a specified output path.


Technology Stack : zipfile

Code Type : File processing

Code Difficulty : Intermediate


                
                    
def zip_file(file_path, output_path):
    import zipfile
    with zipfile.ZipFile(output_path, 'w') as zipf:
        zipf.write(file_path, arcname=file_path.split('/')[-1])
    return f'Zip file created at {output_path}'                
              
Tags: