Support counters in image folder names
This commit is contained in:
@@ -37,17 +37,18 @@ def _next_counter_for_relative_path(base_directory, relative_template):
|
||||
relative_template = str(relative_template).replace("\\", "/")
|
||||
if "%counter%" not in relative_template:
|
||||
return 1
|
||||
template = relative_template.replace("%counter%", "*")
|
||||
parent = Path(base_directory) / Path(template).parent
|
||||
stem = Path(template).name
|
||||
if not parent.exists():
|
||||
base = Path(base_directory)
|
||||
if not base.exists():
|
||||
return 1
|
||||
pattern = re.compile(re.escape(stem).replace(r"\*", r"(\d+)") + r"(?:\.[^.]+)?$")
|
||||
pattern = re.compile(
|
||||
re.escape(relative_template).replace(re.escape("%counter%"), r"(\d+)")
|
||||
)
|
||||
highest = 0
|
||||
for path in parent.iterdir():
|
||||
for path in base.rglob("*"):
|
||||
if not path.is_file():
|
||||
continue
|
||||
match = pattern.match(path.name)
|
||||
relative_path = path.relative_to(base).as_posix()
|
||||
match = pattern.fullmatch(relative_path)
|
||||
if match:
|
||||
highest = max(highest, int(match.group(1)))
|
||||
return highest + 1
|
||||
|
||||
Reference in New Issue
Block a user