From 4d5183063c737023308f85f7056261a758046104 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Thu, 28 Jul 2022 21:30:31 +0400 Subject: [PATCH] Create images directory if doesn't exist, to store image search results --- src/search_type/image_search.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/search_type/image_search.py b/src/search_type/image_search.py index b0777612..8d10a51f 100644 --- a/src/search_type/image_search.py +++ b/src/search_type/image_search.py @@ -190,6 +190,10 @@ def collate_results(hits, image_names, output_directory, image_files_url, count= target_image_name = f"{index}{source_path.suffix}" target_path = resolve_absolute_path(f"{output_directory}/{target_image_name}") + # Create output directory, if it doesn't exist + if not target_path.parent.exists(): + target_path.parent.mkdir(exist_ok=True) + # Copy the image to the output directory shutil.copy(source_path, target_path)