Path: blob/main/tests/netedit/scripts/copyConfigs/script.py
193874 views
#!/usr/bin/env python1# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo2# Copyright (C) 2025-2026 German Aerospace Center (DLR) and others.3# This program and the accompanying materials are made available under the4# terms of the Eclipse Public License 2.0 which is available at5# https://www.eclipse.org/legal/epl-2.0/6# This Source Code may also be made available under the following Secondary7# Licenses when the conditions for such availability set forth in the Eclipse8# Public License 2.0 are satisfied: GNU General Public License, version 29# or later which is available at10# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html11# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1213# @file script.py14# @author Pablo Alvarez Lopez15# @date 2025-12-051617import os18import shutil19import sys202122def copy_file_to_matching_folders(root_path, target_folder_name, source_file_path):23"""24Traverses root_path, looks for folders matching target_folder_name,25and copies source_file_path into them.26"""27# 1. Validate inputs28if not os.path.isdir(root_path):29print(f"Error: The root path '{root_path}' is not a valid directory.")30sys.exit(1)3132if not os.path.isfile(source_file_path):33print(f"Error: The file '{source_file_path}' does not exist.")34sys.exit(1)3536print(f"Scanning '{root_path}' for folders named '{target_folder_name}'...")3738copied_count = 03940# 2. Walk through the directory tree41for current_root, dirs, files in os.walk(root_path):42# Check if the target folder exists in the current directory's subdirectories43if target_folder_name in dirs:44destination_folder = os.path.join(current_root, target_folder_name)4546try:47# 3. Copy the file48shutil.copy2(source_file_path, destination_folder)49print(f"✅ Copied file to: {destination_folder}")50copied_count += 151except Exception as e:52print(f"❌ Failed to copy to {destination_folder}: {e}")5354print(f"\nDone! File copied to {copied_count} location(s).")555657def main():5859# Run the function60copy_file_to_matching_folders("D:/Netedit_dev/tests/netedit/elements/demands", "volatile_recomputing",61"D:/Netedit_dev/tests/netedit/scripts/copyConfigs/netedit_A.netecfg")626364if __name__ == "__main__":65main()666768