This commit is contained in:
2025-11-21 16:56:11 +01:00
parent d43e502710
commit d4894fde95
2 changed files with 103 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
import os
from pathlib import Path
# ==========================
# CONFIG
# ==========================
FOLDER_1 = Path(r"U:\Dropbox\Ordinace\Dokumentace_ke_zpracování")
FOLDER_2 = Path(r"U:\Dropbox\Ordinace\Dokumentace_ke_zpracování\MP")
TRIANGLE = ""
# Set to True for testing (no changes), False to really rename
DRY_RUN = True
def main():
# ---- Collect files in FOLDER_1 (top level only)
files_folder1 = [f for f in FOLDER_1.iterdir() if f.is_file()]
names_folder1 = {f.name.lower() for f in files_folder1}
# ---- Collect ALL files in FOLDER_2 (recursive)
files_folder2 = [f for f in FOLDER_2.rglob("*") if f.is_file()]
actions = [] # store what would be renamed
for file2 in files_folder2:
original_name = file2.name
lower_name = original_name.lower()
# Skip if already starts with ▲
if original_name.startswith(TRIANGLE):
continue
# Check if the filename exists in Folder 1
if lower_name in names_folder1:
new_name = TRIANGLE + original_name
new_path = file2.with_name(new_name)
actions.append((file2, new_path))
if DRY_RUN:
print(f"[DRY RUN] Would rename: {file2}{new_path}")
else:
print(f"Renaming: {file2}{new_path}")
file2.rename(new_path)
print("\n===============================")
if DRY_RUN:
print(f"DRY RUN COMPLETE — {len(actions)} file(s) would be renamed.")
else:
print(f"DONE — {len(actions)} file(s) renamed.")
print("===============================")
if __name__ == "__main__":
main()