From e42d92f2318b0fa9c9d7a9d603f9367874c3e9a1 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Tue, 3 May 2022 22:04:06 +0300 Subject: [PATCH] check exceptions --- image_classifier/image_classifier.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/image_classifier/image_classifier.py b/image_classifier/image_classifier.py index 3c34aa9..1e2a365 100755 --- a/image_classifier/image_classifier.py +++ b/image_classifier/image_classifier.py @@ -128,13 +128,19 @@ class image_classifier: os.makedirs(person_path) self._log.info(f"Copying file '{file}' to person '{person}' folder,\ '{person_path}'...") - shutil.copy(file, person_path) + try: + shutil.copy(file, person_path) + except FileNotFoundError as error: + self._log.error(f"Error copying. File not found. {error}") if not self.no_move: if os.path.exists(os.path.join(new_path, filename)): self._log.debug(f"Destination '{new_path}/{filename}' exists, removing it...") os.remove(os.path.join(new_path, filename)) self._log.info(f"Moving file '{file}' to '{new_path}'...") - shutil.move(file, new_path) + try: + shutil.move(file, new_path) + except FileNotFoundError as error: + self._log.error(f"Error copying. File not found. {error}") else: self._log.info(f"NOT moving file '{file}' to '{new_path}' because of --no-move")