updated the reorganize script to handle nested folders inside of template files like 'YYYY' Income Documents > 2016 > Joe Shmo 2016
This commit is contained in:
@@ -36,6 +36,10 @@ from fccs_config import (
|
||||
|
||||
# Regex for the creation date field (MM-DD-YYYY) bounded by underscores
|
||||
_DATE_RE = re.compile(r"_(\d{2}-\d{2}-\d{4})_")
|
||||
# Trailing "[Subfolder Name]" on the folder field — FCCS encodes nested
|
||||
# subfolders (e.g. Income Documents > 2016 > "4201 N Beach Street, LLC") as
|
||||
# "2016 Income Documents[4201 N Beach Street, LLC]" in the export filename.
|
||||
_SUBFOLDER_RE = re.compile(r"\[([^\[\]]+)\]$")
|
||||
|
||||
|
||||
def parse_filename(filename, folder_patterns):
|
||||
@@ -81,17 +85,29 @@ def parse_filename(filename, folder_patterns):
|
||||
after_date_pos = m.start() - 1 + len("_") + len(date_str) + len("_")
|
||||
doc_name = rest[after_date_pos:]
|
||||
|
||||
# Try each folder pattern against the end of before_date
|
||||
# Peel any trailing [Subfolder] groups off the folder field so the
|
||||
# remainder can match a template; each becomes one more nested path
|
||||
# component (in order, so "a[b][c]" nests as a/b/c).
|
||||
folder_text = before_date
|
||||
sub_parts = []
|
||||
while True:
|
||||
sm = _SUBFOLDER_RE.search(folder_text)
|
||||
if not sm:
|
||||
break
|
||||
sub_parts.insert(0, sm.group(1))
|
||||
folder_text = folder_text[: sm.start()]
|
||||
|
||||
# Try each folder pattern against the end of the folder text
|
||||
for pattern, template_name, folder_type in folder_patterns:
|
||||
folder_match = pattern.search(before_date)
|
||||
if folder_match and folder_match.end() == len(before_date):
|
||||
folder_match = pattern.search(folder_text)
|
||||
if folder_match and folder_match.end() == len(folder_text):
|
||||
# Folder matched at the end — check for underscore separator before it
|
||||
folder_start = folder_match.start()
|
||||
if folder_start > 0 and before_date[folder_start - 1] == "_":
|
||||
client_name = before_date[: folder_start - 1]
|
||||
if folder_start > 0 and folder_text[folder_start - 1] == "_":
|
||||
client_name = folder_text[: folder_start - 1]
|
||||
folder_parts = decompose_folder_path(
|
||||
folder_match, folder_type, template_name
|
||||
)
|
||||
) + tuple(sub_parts)
|
||||
return (drawer_id, client_name, folder_parts, date_str, doc_name + ext)
|
||||
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user