# -*- coding:utf-8 -*- # @Author len # @Create 2023/11/15 16:28 import os # The directory where your JSON files are stored json_directory = r'D:\Waste\嵌入式\数据集\车型\new_jpg\json' # The directory where your PNG files are stored png_directory = r'D:\Waste\嵌入式\数据集\车型\提亮' # Get a list of json filenames without the extension json_files = [f.split('.')[0] for f in os.listdir(json_directory) if f.endswith('.json')] # Get a list of png filenames without the extension png_files = [f.split('.')[0] for f in os.listdir(png_directory) if f.endswith('.png')] # Rename the JSON files to match the PNG file names for json_file in json_files: # Construct the new name based on the PNG files # Assuming the numbering is consistent between the files # and that the only difference is the prefix 'brighter_' new_name = json_file.replace('chexing_static', 'brighter_chexing_static') if new_name in png_files: os.rename(os.path.join(json_directory, json_file + '.json'), os.path.join(json_directory, new_name + '.json')) print("JSON files have been renamed to match PNG files.")