From 766a841f3cfbc991f3c523be366014ce9d73a2af Mon Sep 17 00:00:00 2001 From: Tristan Smith Date: Sun, 7 Apr 2024 22:27:17 -0400 Subject: [PATCH] bottle cap flip flops --- unzipdir.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 unzipdir.py diff --git a/unzipdir.py b/unzipdir.py new file mode 100644 index 0000000..09fa79e --- /dev/null +++ b/unzipdir.py @@ -0,0 +1,22 @@ +import sys +import zipfile +import os +from pathlib import Path + +def unzip_files(directory_path): + for zip_file in Path(directory_path).glob('*.zip'): + folder_name = zip_file.stem # Get the file name without the .zip extension + output_dir = zip_file.parent / folder_name # Path for the output directory + os.makedirs(output_dir, exist_ok=True) # Create the directory if it doesn't exist + + with zipfile.ZipFile(zip_file, 'r') as zip_ref: + zip_ref.extractall(output_dir) + print(f"Extracted {zip_file.name} to {output_dir}") + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python script.py ") + sys.exit(1) + + directory_path = sys.argv[1] + unzip_files(directory_path)