# -*- coding: utf-8 -*- """ Created on Thu Aug 13 16:11:44 2026 @author: muhuri """ # -------------------------------------------------------------- # This script recursively finds every index.html under C:\Explore, # determines a prefix from the containing folder, and copies # each file into C:\Explore\HTML with names such as SAS_index.html, # Python_index.html, etc. # ----------------------------------------------------------------- from pathlib import Path import shutil # -------------------------------------------------- # Root and destination folders # -------------------------------------------------- root = Path(r"C:\Explore") dest = Path(r"C:\Explore\HTML") dest.mkdir(exist_ok=True) # -------------------------------------------------- # The prefix_map below is a Python dictionary, # which stores the key value pairs. The prefix_map # is a lookup table that lets us translate folder names # into the prefixes we want to use for the copied # HTML filenames. # -------------------------------------------------- prefix_map = { "Explore": "Explore", "SAS": "SAS", "SUDAAN": "SUDAAN", "Python": "Python", "DataHive": "DataHive", "stata-complex-surveys": "Stata", "r-basics": "R", "HTML": "HTML", "BDIndiaCensusHistorical": "BDM", "BDViolenceAgainstMinority": "BDV" } # -------------------------------------------------- # Find, copy and rename all index.html files # -------------------------------------------------- for file in root.rglob("index.html"): folder_name = file.parent.name prefix = prefix_map.get(folder_name, folder_name) new_name = f"{prefix}_index.html" destination_file = dest / new_name shutil.copy2(file, destination_file) print("Copied:") print(f" From: {file}") print(f" To : {destination_file}") print() print("Done.")