Compress File into Zip

  • Share this:

Code introduction


This function accepts an input file path and an output file path, compresses the input file into a zip file and saves it to the output path.


Technology Stack : zipfile

Code Type : File compression

Code Difficulty : Intermediate


                
                    
def zip_file(input_file, output_file):
    import zipfile
    with zipfile.ZipFile(output_file, 'w') as zipf:
        zipf.write(input_file, arcname=input_file)
    return output_file                
              
Tags: