import os import shutil SOURCE_DIR = os.path.abspath("assets/slike/ZA_PREGLED") DEST_BASE = os.path.abspath("assets/slike/glavna_referenca") # Mapping rules: Keyword -> Destination Subfolder RULES = { # Characters "kai": "characters/kai", "ana": "characters/ana", "gronk": "characters/gronk", "susi": "characters/susi", "zombie": "characters/enemies", "boss": "biomes/bosses", # General boss folder or specifics "druid": "characters/npc/magical", "priest": "characters/npc/magical", "witch": "characters/npc/magical", "baker": "characters/npc/town", "blacksmith": "characters/npc/town", "trader": "characters/npc/town", "merchant": "characters/npc/town", "fisherman": "characters/npc/town", "scientist": "characters/npc/special", "guide": "characters/npc/special", "hunter": "characters/npc/special", "chief": "characters/npc/special", "pharaoh": "characters/npc/special", "stalker": "characters/npc/special", # Animals "cow": "animals/farm", "pig": "animals/farm", "chicken": "animals/farm", "sheep": "animals/farm", "goat": "animals/farm", "horse": "animals/farm", "wolf": "animals/wild", "bear": "animals/wild", "fox": "animals/wild", "deer": "animals/wild", "rabbit": "animals/wild", "bird": "animals/wild", # Biomes/Environment "tree": "biomes/02_forest/vegetation", # Default placement, user can refine "grass": "biomes/01_grassland/terrain", "rock": "environment/narava", "stone": "environment/narava", "water": "environment/narava", "desert": "biomes/04_desert", "swamp": "biomes/03_swamp", "snow": "biomes/06_snow", "volcan": "biomes/05_mountain", # Or volcanic biome # Items "tool": "items/tools", "weapon": "items/weapons", "food": "items/food", "seed": "items/farming/seeds", "crop": "items/farming/crops", "potion": "items/consumables", "book": "items/special", "key": "items/special", # Buildings "house": "buildings/town", "shop": "buildings/town", "hut": "buildings/wild", "tent": "buildings/camping", "ruin": "buildings/ruins", "wall": "buildings/structures", # UI "icon": "ui/icons", "button": "ui/buttons", "panel": "ui/panels", "menu": "ui/menus", } def organize_za_pregled(): if not os.path.exists(SOURCE_DIR): print("❌ Source directory not found!") return print("🔓 Unlocking destination folder just in case...") os.system(f"chmod -R u+w {DEST_BASE}") print(f"📦 Organizing {SOURCE_DIR}...") moved_count = 0 skipped_count = 0 files = [f for f in os.listdir(SOURCE_DIR) if os.path.isfile(os.path.join(SOURCE_DIR, f))] for filename in files: if filename.startswith("."): continue # Skip hidden files src_path = os.path.join(SOURCE_DIR, filename) lower_name = filename.lower() destination = None # Check rules for keyword, relative_dest in RULES.items(): if keyword in lower_name: destination = os.path.join(DEST_BASE, relative_dest) break # Default fallback if no rule matches but looks like something if not destination: if "anim" in lower_name: destination = os.path.join(DEST_BASE, "_NESORTIRANO/animations") elif ".png" in lower_name or ".jpg" in lower_name: destination = os.path.join(DEST_BASE, "_NESORTIRANO/images") else: destination = os.path.join(DEST_BASE, "_NESORTIRANO/other") # Move file if destination: if not os.path.exists(destination): os.makedirs(destination) try: dest_path = os.path.join(destination, filename) # Handle duplicates if os.path.exists(dest_path): base, ext = os.path.splitext(filename) dest_path = os.path.join(destination, f"{base}_COPY{ext}") shutil.move(src_path, dest_path) moved_count += 1 if moved_count % 100 == 0: print(f" Moved {moved_count} files...") except Exception as e: print(f"❌ Error moving {filename}: {e}") skipped_count += 1 else: skipped_count += 1 print(f"✨ DONE! Moved {moved_count} files. Skipped {skipped_count}.") print("🔒 Don't forget to lock the folder again if needed!") if __name__ == "__main__": organize_za_pregled()