From 7004c4007190849e6391e8b35a386f5275946fb3 Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Fri, 5 Apr 2024 23:28:55 -0400 Subject: [PATCH] zipremove processes entire folders --- zipremove.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/zipremove.py b/zipremove.py index b8a9bdc..48a5764 100644 --- a/zipremove.py +++ b/zipremove.py @@ -3,6 +3,7 @@ import os import sys import tempfile from pathlib import Path +import shutil def filter_and_repack_zip(zip_path): temp_dir = tempfile.TemporaryDirectory() @@ -13,8 +14,10 @@ def filter_and_repack_zip(zip_path): for file in original_zip.namelist(): if "(USA" in file or "(USA, Europe)" in file: new_zip.writestr(file, original_zip.read(file)) - - os.replace(new_zip_path, zip_path) + + # Remove the original file and move the new file to the original location + os.remove(zip_path) + shutil.move(new_zip_path, zip_path) def process_directory(directory_path): for zip_file in Path(directory_path).glob('*.zip'):