# -*- coding: utf-8 -*- import os, zipfile, time SRC = r"D:\_备份\水利智学系统_精简备份_20261120" ZIP = r"D:\_备份\水利智学系统_精简备份_20261120.zip" if os.path.exists(ZIP): os.remove(ZIP) t0 = time.time() n = 0 total = 0 with zipfile.ZipFile(ZIP, "w", zipfile.ZIP_DEFLATED, compresslevel=1) as z: for root, dirs, files in os.walk(SRC): for f in files: p = os.path.join(root, f) try: size = os.path.getsize(p) except Exception: continue arc = os.path.relpath(p, SRC) try: z.write(p, arc) n += 1 total += size except Exception as e: print("SKIP", p, e) print("files=%d src_GB=%.2f zip_MB=%.1f secs=%d" % ( n, total / 1073741824, os.path.getsize(ZIP) / 1048576, time.time() - t0))