check exceptions

This commit is contained in:
Antonio J. Delgado 2022-05-03 22:04:06 +03:00
parent 056a7179a9
commit e42d92f231

View file

@ -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")