🏗️ Clean demo asset filenames - remove timestamps
Renamed 45 files to remove timestamp suffixes - kai_run_east_1_stylea_1767137189376.png → kai_run_east_1_stylea.png - etc... Creates clean, organized asset structure Added organize_demo_assets.py script
This commit is contained in:
120
scripts/organize_demo_assets.py
Normal file
120
scripts/organize_demo_assets.py
Normal file
@@ -0,0 +1,120 @@
|
||||
#!/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/images/demo")
|
||||
|
||||
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()
|
||||
Reference in New Issue
Block a user