From f8692226869594b71fed6ec7a2c999ff74095dcf Mon Sep 17 00:00:00 2001 From: caiwx86 Date: Thu, 14 Nov 2024 23:36:12 +0800 Subject: [PATCH] fix --- Comics/_utils/utils.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Comics/_utils/utils.py b/Comics/_utils/utils.py index b8f8446..194d1fb 100644 --- a/Comics/_utils/utils.py +++ b/Comics/_utils/utils.py @@ -488,22 +488,30 @@ class CBZUtils: return data @classmethod - def zip_compression(cls, source_dir=None, target_file=None, remove=True): + def zip_compression(cls, source_dir=None, target_file=None, remove=True, min_files=1): target_dir = os.path.dirname(target_file) if not os.path.exists(target_dir): os.makedirs(target_dir) + count_files = 0 if not os.path.exists(target_file) and source_dir is not None: with ZipFile(target_file, mode='w') as zf: for path, dir_names, filenames in os.walk(source_dir): + count_files = len(filenames) path = Path(path) arc_dir = path.relative_to(source_dir) y = 0 for filename in filenames: y = y + 1 - print("打包中:" + str(y) + "/" + str(len(filenames)), os.path.join(source_dir, filename)) + print("打包中:" + str(y) + "/" + str(count_files), os.path.join(source_dir, filename)) zf.write(path.joinpath(filename), arc_dir.joinpath(filename)) zf.close() logging.info(f"打包完成:{target_file}") + if count_files <= min_files: + try: + os.path.remove(target_file) + logging.info(f"{target_file} 文件不符合最小文件数规则,已删除") + except Exception as e: + logging.error(f"{target_file} 删除报错") @DeprecationWarning @classmethod