#!/usr/bin/env python3 """ Organize demo assets - rename and subfolder Removes timestamps and organizes into proper structure """ import re from pathlib import Path import shutil def rename_and_organize_demo(): """Organize demo assets into subfolders with clean names""" demo_base = Path("assets/slike") categories = { 'characters': demo_base / 'characters', 'buildings': demo_base / 'buildings', 'terrain': demo_base / 'terrain', 'environment': demo_base / 'environment' } stats = {'renamed': 0, 'organized': 0} for category_name, category_path in categories.items(): if not category_path.exists(): continue print(f"\nšŸ“‚ {category_name}/") # Process all PNG files for png_file in sorted(category_path.glob('*.png')): # Skip if already in subfolder if png_file.parent != category_path: continue filename = png_file.name # Remove timestamp (13 digits at end before .png) clean_name = re.sub(r'_\d{13}\.png$', '.png', filename) if clean_name != filename: stats['renamed'] += 1 print(f" āœļø {filename} → {clean_name}") # Rename file new_path = png_file.parent / clean_name if new_path.exists(): # If target exists, keep the newer one print(f" āš ļø Target exists, keeping newer") if png_file.stat().st_mtime > new_path.stat().st_mtime: new_path.unlink() png_file.rename(new_path) else: png_file.unlink() else: png_file.rename(new_path) print(f"\nāœ… Cleaned {stats['renamed']} filenames") # NOW organize into subfolders print("\n" + "="*70) print("šŸ“ ORGANIZING INTO SUBFOLDERS") print("="*70) for category_name, category_path in categories.items(): print(f"\nšŸ“‚ {category_name}/") # Get all PNG files again (with clean names now) files = sorted(category_path.glob('*.png')) if not files: print(" āœ“ No files to organize") continue # Group by base name groups = {} for f in files: # Extract base name (before _styleA or _styleB) match = re.match(r'(.+?)_(styleA|styleB)\.png$', f.name) if match: base_name = match.group(1) if base_name not in groups: groups[base_name] = [] groups[base_name].append(f) # Create subfolders and move files for base_name, file_list in sorted(groups.items()): if len(file_list) < 2: continue # Skip if not dual-style subfolder = category_path / base_name subfolder.mkdir(exist_ok=True) print(f"\n šŸ“ {base_name}/ ({len(file_list)} files)") for file_path in file_list: # New organized name if 'styleA' in file_path.name: new_name = f"{base_name}_styleA_1024x1024.png" else: new_name = f"{base_name}_styleB_1024x1024.png" target = subfolder / new_name if not target.exists(): file_path.rename(target) print(f" → {new_name}") stats['organized'] += 1 else: print(f" ā­ļø Already exists: {new_name}") print("\n" + "="*70) print(f"āœ… COMPLETE!") print(f" Renamed: {stats['renamed']}") print(f" Organized: {stats['organized']}") print("="*70) if __name__ == "__main__": rename_and_organize_demo()