File size: 443 Bytes
c985ba4
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
import zipfile
import os


def zip_folder(source_folder, zip_dir):
    f = zipfile.ZipFile(zip_dir, 'w', zipfile.ZIP_DEFLATED)
    pre_len = len(os.path.dirname(source_folder))
    for dirpath, dirnames, filenames in os.walk(source_folder):
        for filename in filenames:
            pathfile = os.path.join(dirpath, filename)
            arcname = pathfile[pre_len:].strip(os.path.sep)
            f.write(pathfile, arcname)
    f.close()