日本語モード

このページは日本語モードに設定されています。

リネームツール (Python)


import os
import shutil

def rename_files(base_path):
    combined_path = os.path.join(base_path, "AA")
    if not os.path.exists(combined_path):
        os.makedirs(combined_path)

    for folder in os.listdir(base_path):
        folder_path = os.path.join(base_path, folder)
        if os.path.isdir(folder_path) and folder.startswith("AA") and len(folder) == 4:
            for file_name in os.listdir(folder_path):
                src_file = os.path.join(folder_path, file_name)
                if os.path.isfile(src_file):
                    new_file_name = f"{folder[2:]}-{file_name}"
                    dest_file = os.path.join(combined_path, new_file_name)
                    shutil.move(src_file, dest_file)