import os
import re

folder = r"D:\listeremojis\sprotes"

for filename in os.listdir(folder):
    if os.path.isfile(os.path.join(folder, filename)):
        name, ext = os.path.splitext(filename)
        # Remove leading numbers, spaces, and hyphens
        new_name = re.sub(r'^\d+\s*-\s*', '', name)
        # Remove spaces and hyphens from the rest of the name
        new_name = new_name.replace(' ', '').replace('-', '')
        new_filename = f"{new_name}{ext}"
        counter = 2
        # If file exists, append a number
        while os.path.exists(os.path.join(folder, new_filename)):
            new_filename = f"{new_name}{counter}{ext}"
            counter += 1
        os.rename(
            os.path.join(folder, filename),
            os.path.join(folder, new_filename)
        )