Fix: Improve filename sanitization to prevent Windows 8.3 short names on Synology

This commit is contained in:
2026-01-06 23:36:11 +09:00
parent 92276396ce
commit f2aa78fa48
2 changed files with 16 additions and 6 deletions

View File

@@ -58,11 +58,21 @@ class Util(object):
@staticmethod
def change_text_for_use_filename(text):
# text = text.replace('/', '')
# 2021-07-31 X:X
# text = text.replace(':', ' ')
text = re.sub('[\\/:*?\"<>|]', ' ', text).strip()
text = re.sub("\s{2,}", ' ', text)
# 1. Remove/replace Windows-forbidden characters
text = re.sub('[\\/:*?"<>|]', ' ', text)
# 2. Remove consecutive dots (.. → .)
text = re.sub(r'\.{2,}', '.', text)
# 3. Remove leading/trailing dots and spaces
text = text.strip('. ')
# 4. Collapse multiple spaces to single space
text = re.sub(r'\s{2,}', ' ', text)
# 5. Remove any remaining trailing dots (after space collapse)
text = text.rstrip('.')
return text
@staticmethod