Z230
This commit is contained in:
57
RenameMedevioPrilohy/10 RenameMedevioPrilohy.py
Normal file
57
RenameMedevioPrilohy/10 RenameMedevioPrilohy.py
Normal file
@@ -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.")
|
||||
Reference in New Issue
Block a user