import os

base_dir = 'results/super_glue'

if False:
    for dirpath, dirnames, filenames in os.walk(base_dir):

        seeds = [d for d in dirnames if d.isdigit()]

        for seed in seeds:
            seed_path = os.path.join(dirpath, seed)
            dir_seed = os.path.join(dirpath, seed)

            for sub_dirpath, sub_dirnames, sub_filenames in os.walk(seed_path):

                # rename 'record' folder
                if 'record' in sub_dirnames:
                    record_path = os.path.join(sub_dirpath, 'record')
                    new_record_path = os.path.join(sub_dirpath, 'record_old3')
                    print(f'Renaming {record_path} to {new_record_path}')
                    os.rename(record_path, new_record_path)


import os
import shutil

base_dir = 'results/super_glue'

for dirpath, dirnames, filenames in os.walk(base_dir):
    seeds = [d for d in dirnames if d.isdigit()]

    for seed in seeds:
        seed_path = os.path.join(dirpath, seed)

        for sub_dirpath, sub_dirnames, sub_filenames in os.walk(seed_path):
            # find folders starting with "record_old"
            old_records = [d for d in sub_dirnames if d.startswith("record_old")]

            for old in old_records:
                old_path = os.path.join(sub_dirpath, old)
                print(f'Deleting {old_path}')
                shutil.rmtree(old_path)
