import os
import random
import string

def random_string(length=10):
    return ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(length))

def assign_random_names(path):
    for filename in os.listdir(path):
        file_path = os.path.join(path, filename)
        if os.path.isfile(file_path):
            random_name = f"{random_string()}.{filename.split('.')[-1]}"
            random_file_path = os.path.join(path, random_name)
            os.rename(file_path, random_file_path)

def rename_files(path):
    i = 10001
    for filename in os.listdir(path):
        file_path = os.path.join(path, filename)
        if os.path.isfile(file_path):
            new_filename = f"img{i}.{filename.split('.')[-1]}"
            new_file_path = os.path.join(path, new_filename)
            os.rename(file_path, new_file_path)
            i += 1

folder_path = r'C:\sdxl kaggle dreambooth\selected imgs'  # Replace with your folder path

# First assign random names
assign_random_names(folder_path)

# Then rename the files
rename_files(folder_path)
