Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python zip folder

import shutil
shutil.make_archive(output_filename, 'zip', dir_name)
Comment

python zip folder

import os
import zipfile

def zip_directory(folder_path, zip_path):
    with zipfile.ZipFile(zip_path, mode='w') as zipf:
        len_dir_path = len(folder_path)
        for root, _, files in os.walk(folder_path):
            for file in files:
                file_path = os.path.join(root, file)
                zipf.write(file_path, file_path[len_dir_path:])
                
zip_directory('C:/FolderToZip', 'C:/Folder.zip')
Comment

python zip folder

#!/usr/bin/env python
import os
import zipfile

def zipdir(path, ziph):
    # ziph is zipfile handle
    for root, dirs, files in os.walk(path):
        for file in files:
            ziph.write(os.path.join(root, file))

if __name__ == '__main__':
    zipf = zipfile.ZipFile('Python.zip', 'w', zipfile.ZIP_DEFLATED)
    zipdir('tmp/', zipf)
    zipf.close()
Comment

zip a directory in python

shutil.make_archive(output_filename, 'zip', dir_name)
Comment

PREVIOUS NEXT
Code Example
Python :: google translator api pyhton 
Python :: python iterate files 
Python :: python pandas column where 
Python :: how to use function in python 
Python :: how to create an empty list of certain length in python 
Python :: midpoint 
Python :: python tkinter get image size 
Python :: how to convert pdf to word using python 
Python :: json decode py 
Python :: how to use fastapi ApiClient with pytest 
Python :: delete a column in pandas 
Python :: python pandas csv append 
Python :: selenium select element by id 
Python :: number of days in a month python 
Python :: python replace line in file 
Python :: how to pass parameters in python script 
Python :: python sort dictionary by value 
Python :: matplotlib pyplot comment on plot 
Python :: different states of a button tkinter 
Python :: run in another thread decorator 
Python :: how to fix valueerror in python 
Python :: python plot two lines with different y axis 
Python :: write lines python with line breaks 
Python :: How to combine train and Test dataset in python 
Python :: how to restart loop python 
Python :: python assert is not null 
Python :: group by pandas count 
Python :: Math Module tan() Function in python 
Python :: how to make program speak in python 
Python :: python last 3 list elements 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =