From 186c98fd0d64ed685c2cc1784809a33db0483b16 Mon Sep 17 00:00:00 2001 From: "vladimir.buzalka" Date: Wed, 7 Jan 2026 08:30:39 +0100 Subject: [PATCH] Z230 --- 50 Různé testy/10 RenameFoldersTriangles.py | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 50 Různé testy/10 RenameFoldersTriangles.py diff --git a/50 Různé testy/10 RenameFoldersTriangles.py b/50 Různé testy/10 RenameFoldersTriangles.py new file mode 100644 index 0000000..8c1c8cb --- /dev/null +++ b/50 Různé testy/10 RenameFoldersTriangles.py @@ -0,0 +1,46 @@ +import os +from pathlib import Path + +# Define the target directory +target_path = Path(r"U:\Dropbox\Ordinace\Dokumentace_ke_zpracování\MP") + + +def rename_folders(): + # Ensure the path exists + if not target_path.exists(): + print(f"Error: The path {target_path} does not exist.") + return + + # Iterate through items in the directory + for folder in target_path.iterdir(): + # Only process directories + if folder.is_dir(): + original_name = folder.name + + # Check if name starts with the triangle + if original_name.startswith("▲"): + # 1. Remove the triangle from the start + name_without_tri = original_name[1:] + + # 2. Prepare the name to be at least 10 chars long + # (so the triangle can sit at index 10 / position 11) + clean_name = name_without_tri.ljust(10) + + # 3. Construct new name: first 10 chars + triangle + the rest + new_name = clean_name[:10] + "▲" + clean_name[10:] + + # Remove trailing spaces if the original name was short + # but you don't want extra spaces at the very end + new_name = new_name.rstrip() + + new_folder_path = folder.parent / new_name + + try: + print(f"Renaming: '{original_name}' -> '{new_name}'") + folder.rename(new_folder_path) + except Exception as e: + print(f"Could not rename {original_name}: {e}") + + +if __name__ == "__main__": + rename_folders() \ No newline at end of file