Compress File to Zip Format

  • Share this:

Code introduction


This function compresses a specified file into a zip format and outputs the path of the compressed file.


Technology Stack : zipfile

Code Type : Function

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)
    return f"File {file_path} has been zipped to {output_path}"                
              
Tags: