ok
This commit is contained in:
53
scripts/flatten_biomes_total.py
Normal file
53
scripts/flatten_biomes_total.py
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
TARGET = "assets/slike/biomi"
|
||||
|
||||
def flatten_biomes():
|
||||
print(f"🚀 FLATTENING BIOME STRUCTURE in {TARGET}...")
|
||||
|
||||
if not os.path.exists(TARGET):
|
||||
return
|
||||
|
||||
moved = 0
|
||||
# Iterate numbered folders
|
||||
for folder in os.listdir(TARGET):
|
||||
folder_path = os.path.join(TARGET, folder)
|
||||
if not os.path.isdir(folder_path):
|
||||
continue
|
||||
|
||||
print(f" 📦 Processing {folder}...")
|
||||
|
||||
for file in os.listdir(folder_path):
|
||||
src = os.path.join(folder_path, file)
|
||||
if os.path.isdir(src):
|
||||
print(f" ! Removing leftover dir {file}")
|
||||
# shutil.rmtree(src) # Should be empty/flat by now
|
||||
continue
|
||||
|
||||
# Move to biomi root
|
||||
# Name strategy: Prepend folder name ensures uniqueness + context
|
||||
# e.g. 20_Base_Farm_cow.png
|
||||
new_name = f"{folder}_{file}"
|
||||
dst = os.path.join(TARGET, new_name)
|
||||
|
||||
try:
|
||||
shutil.move(src, dst)
|
||||
moved += 1
|
||||
except Exception as e:
|
||||
print(f"Error {file}: {e}")
|
||||
|
||||
# Remove folder
|
||||
try:
|
||||
os.rmdir(folder_path)
|
||||
print(f" 🗑️ Removed {folder}")
|
||||
except:
|
||||
print(f" ❌ Could not remove {folder} (not empty?)")
|
||||
|
||||
print("="*40)
|
||||
print(f"✅ BIOMES FLATTENED. Moved {moved} images to {TARGET}.")
|
||||
print("="*40)
|
||||
|
||||
if __name__ == "__main__":
|
||||
flatten_biomes()
|
||||
Reference in New Issue
Block a user