Creating Zip Files with Given Paths

  • Share this:

Code introduction


This function takes two arguments: the path to the input file and the path to the output file. The function first uses the `zipfile` module to create a zip file named after the input file path and adds the file to the zip file. Then, it creates a new zip file named after the output path and performs the same operation.


Technology Stack : zipfile

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip_file(file_path, output_path):
    import zipfile
    with zipfile.ZipFile(file_path, 'w') as zipf:
        zipf.write(file_path, arcname=file_path)
    with zipfile.ZipFile(output_path, 'w') as zipf:
        zipf.write(file_path, arcname=file_path)                
              
Tags: