import os, glob, shutil
BASE = os.path.dirname(os.path.abspath(__file__))
out = os.path.join(BASE, "Old Images")
os.makedirs(out, exist_ok=True)
n = 0
for level in ["P1", "P2", "P3", "P4", "P5", "P6"]:
    for f in glob.glob(os.path.join(BASE, level, "*", "_figures.png")):
        folder = os.path.basename(os.path.dirname(f))
        # strip redundant leading "pN-" from folder name
        short = folder
        pre = level.lower() + "-"
        if short.startswith(pre):
            short = short[len(pre):]
        dest = os.path.join(out, "%s.%s.png" % (level, short))
        shutil.copy2(f, dest)
        n += 1
print("copied %d figure sheets into 'New Images/'" % n)
