#!/usr/bin/env python3 import os import random from datetime import date base_directory = '/Users/dancrosby/Documents/headshots/no_profession/' directories = [f'{base_directory}male/', f'{base_directory}female/'] counter = 1 date_str = date.today().strftime('%Y%m%d') for directory in directories: for filename in os.listdir(directory): orig_path = os.path.join(directory, filename) if os.path.isfile(orig_path) and filename.endswith('.png') and 'photorealistic_headshot' in filename: new_filename = f'{date_str}_{counter}_{random.randint(0, 99999999999)}.png' counter = counter + 1 new_path = os.path.join(directory, new_filename) print(f'moving {orig_path} to {new_path}') os.rename(orig_path, new_path)