diff --git a/image_classifier/image_classifier.py b/image_classifier/image_classifier.py index 4aa843c..584d94c 100755 --- a/image_classifier/image_classifier.py +++ b/image_classifier/image_classifier.py @@ -98,11 +98,14 @@ class image_classifier: match = re.search(r'(?P[1-2][0-9]{3})[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P[0-3]?[0-9])', filename) if match: new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) - if new_path: - self._log.info(f"Moving file '{file}' to '{new_path}'...") - shutil.move(file, new_path) - else: - self._log.debug('No new path, so no moving.') + if not new_path: + match = re.search(r'(?P[0-3]?[0-9])[\-/\._]?(?P[0-1]?[0-9])[\-/\._]?(?P[1-2][0-9]{3})', filename) + if match: + new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename) + if not new_path: + new_path = os.path.join(dirname, 'unknown-time', filename) + self._log.info(f"Moving file '{file}' to '{new_path}'...") + shutil.move(file, new_path) else: self._log.debug("Doesn't seem to be an image.")