from pathlib import Path import uuid import json filename_mapping = {} for filename in Path("html_files").glob("*.html"): unique_name = filename.stem.split("_")[2]+ "_" + uuid.uuid4().hex # print (filename.name , unique_name) filename_mapping[filename.name] = unique_name with open("filemapping.json", "w") as js: js.write(json.dumps(filename_mapping)) for filename in Path("html_files").glob("*.html"): new_filename = filename_mapping[filename.name] + ".html" print(f"Rename {filename} to {Path("html_files")/new_filename}") filename.rename(Path("html_files")/new_filename)