From d43e5027101f0078a12c90ce82d979a2681b4d9d Mon Sep 17 00:00:00 2001 From: "vladimir.buzalka" Date: Thu, 20 Nov 2025 10:01:53 +0100 Subject: [PATCH] Z230 --- .../10 RenameMedevioPrilohy.py | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 RenameMedevioPrilohy/10 RenameMedevioPrilohy.py diff --git a/RenameMedevioPrilohy/10 RenameMedevioPrilohy.py b/RenameMedevioPrilohy/10 RenameMedevioPrilohy.py new file mode 100644 index 0000000..7fad288 --- /dev/null +++ b/RenameMedevioPrilohy/10 RenameMedevioPrilohy.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import os +from pathlib import Path + +# ============================== +# CONFIGURATION +# ============================== +BASE_DIR = Path(r"u:\Dropbox\Ordinace\Dokumentace_ke_zpracování\MP") + +# ============================== +# MAIN LOGIC +# ============================== + +def all_files_start_with_triangle(dir_path: Path) -> bool: + """Return True if all files in directory start with ▲""" + for item in dir_path.iterdir(): + if item.is_file(): + if not item.name.startswith("▲"): + return False + return True + + +def process(): + for dir_path in BASE_DIR.iterdir(): + if not dir_path.is_dir(): + continue + + # Skip directories that already have ▲ at position 12 + old_name = dir_path.name + if len(old_name) > 11 and old_name[10:11] == "▲": + continue + + # Check if ALL files start with ▲ + if not all_files_start_with_triangle(dir_path): + continue + + # Insert ▲ after the date (position 10) + # OLD: "2025-11-20 ŠTEPÁN, ..." + # NEW: "2025-11-20▲ ŠTEPÁN, ..." + if len(old_name) < 11: + # Name too short, skip to avoid errors + continue + + new_name = old_name[:10] + "▲" + old_name[10:] + + new_path = dir_path.parent / new_name + + # Rename directory + print(f"Renaming:\n {dir_path.name}\n→ {new_name}") + os.rename(dir_path, new_path) + + +if __name__ == "__main__": + process() + print("\n✓ Done.")