#!/usr/bin/env python1# -*- coding: utf-8 -*-2# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo3# Copyright (C) 2024-2025 German Aerospace Center (DLR) and others.4# This program and the accompanying materials are made available under the5# terms of the Eclipse Public License 2.0 which is available at6# https://www.eclipse.org/legal/epl-2.0/7# This Source Code may also be made available under the following Secondary8# Licenses when the conditions for such availability set forth in the Eclipse9# Public License 2.0 are satisfied: GNU General Public License, version 210# or later which is available at11# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html12# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1314# @file copyElements.py15# @author Pablo Alvarez Lopez16# @date 2024-12-091718import os19import shutil2021# Function to copy a file if a reference file exists in the folder222324def copy_file_if_reference_exists(source_file, base_folder, reference_file):25# Check if the source file exists26if not os.path.isfile(source_file):27print(source_file + " doesn't exist")28return2930# Traverse all folders and subfolders in the base folder31for root, dirs, files in os.walk(base_folder):32for dir_name in dirs:33destination_folder = os.path.join(root, dir_name)34reference_file_path = os.path.join(destination_folder, reference_file)3536# Check if the reference file exists in the folder37if os.path.isfile(reference_file_path):38try:39# Copy the file to the current folder40shutil.copy(source_file, destination_folder)41print(f"File copied to: {destination_folder}")42except Exception:43print("File " + source_file + " cannnot be copied to " + destination_folder)444546# Main block47if __name__ == "__main__":4849# Path of the file to be copied50source_file = r"D:\meandatas.netedit"5152# Path of the base folder where the file will be copied53base_folder = r"D:\SUMO"5455# Name of the reference file that must exist in the folder56reference_file = "routes.netedit"5758# Call the function59copy_file_if_reference_exists(source_file, base_folder, reference_file)606162