Find date in name and no move
This commit is contained in:
parent
ac35fdeb06
commit
4d281c7190
1 changed files with 6 additions and 1 deletions
|
@ -10,6 +10,7 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
|
import re
|
||||||
import click
|
import click
|
||||||
import click_config_file
|
import click_config_file
|
||||||
from logging.handlers import SysLogHandler
|
from logging.handlers import SysLogHandler
|
||||||
|
@ -93,9 +94,13 @@ class image_classifier:
|
||||||
new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename)
|
new_path = os.path.join(dirname, original_date.strftime('%Y/%m/%d'), filename)
|
||||||
self._log.debug(f"New path: {new_path}")
|
self._log.debug(f"New path: {new_path}")
|
||||||
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
os.makedirs(os.path.dirname(new_path), exist_ok=True)
|
||||||
|
if not new_path:
|
||||||
|
match = re.search(r'(?P<year>2[0-9]{3})[\-/\._]?(?P<month>[0-9]{1,2})[\-/\._]?(?P<day>[0-9]{1,2})')
|
||||||
|
if match:
|
||||||
|
new_path = os.path.join(dirname, match.group('year'), match.group('month'), match.group('day'), filename)
|
||||||
if new_path:
|
if new_path:
|
||||||
self._log.info(f"Moving file '{file}' to '{new_path}'...")
|
self._log.info(f"Moving file '{file}' to '{new_path}'...")
|
||||||
shutil.move(file, new_path)
|
#shutil.move(file, new_path)
|
||||||
else:
|
else:
|
||||||
self._log.debug('No new path, so no moving.')
|
self._log.debug('No new path, so no moving.')
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue