website

Website contents
git clone git://git.reagancfischer.dev/website.git
Log | Files | Refs

renumberer.py (670B)


      1 import os
      2 
      3 # Function to rename image files sequentially
      4 def rename_images_sequentially(directory):
      5     counter = 1
      6     for root, _, files in os.walk(directory):
      7         for filename in sorted(files):
      8             if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
      9                 _, ext = os.path.splitext(filename)
     10                 new_name = f'cat{counter}.{ext.strip(".").lower()}'
     11                 old_path = os.path.join(root, filename)
     12                 new_path = os.path.join(root, new_name)
     13                 os.rename(old_path, new_path)
     14                 counter += 1
     15 
     16 # Rename images sequentially in the 'images' directory
     17 rename_images_sequentially('images')