text_plain_output_1.png
import datetime

import os

import os

import os

import zipfile

import os
import zipfile
import datetime
def file2zip(packagePath, zipPath):
    """
  :param packagePath: 文件夹路径
  :param zipPath: 压缩包路径
  :return:
  """
    zip = zipfile.ZipFile(zipPath, 'w', zipfile.ZIP_DEFLATED)
    for path, dirNames, fileNames in os.walk(packagePath):
        fpath = path.replace(packagePath, '')
        for name in fileNames:
            fullName = os.path.join(path, name)
            name = fpath + '\\' + name
            zip.write(fullName, name)
    zip.close()
if __name__ == '__main__':
    packagePath = '/kaggle/working/yolov5-6-1ming/runs/train/exp2'
    zipPath = '/kaggle/working/yolov5s_SE-50-544-simplified-one-layer-only-pedestrians.zip'
    if os.path.exists(zipPath):
        os.remove(zipPath)
    file2zip(packagePath, zipPath)
    print('打包完成')
    print(datetime.datetime.utcnow())