import os import shutil for root, dirs, files in os.walk( '/ZeroCodeProject/apis/basic_api_config'): for file in files: # 如果文件名匹配目标文件名 if file == 'views_function.json': # 返回文件的完整路径 # 源文件的完整路径 source_file_path = os.path.join(root, file) new_name = os.path.basename(os.path.dirname(os.path.dirname(root))) # 目标文件的完整路径 target_file_path = os.path.join( '/ZeroCodeProject/apis/Template_api_service/api_config_folder', new_name + "_" + file) # 复制文件 shutil.copy2(source_file_path, target_file_path)