import os import shutil # 指定文件夹路径 image_folder = 'image' test_folder = 'test' txt_file = 'test_list.txt' # 从文本文件中读取文件名 with open(txt_file, 'r') as file: file_names = file.read().splitlines() # 复制文件 for file_name in file_names: file_name+='.jpg' source_path = os.path.join(image_folder, file_name) destination_path = os.path.join(test_folder, file_name) if os.path.exists(source_path): shutil.copy(source_path, destination_path) print(f'Copied {file_name} to {test_folder}') else: print(f'File {file_name} not found in {image_folder}')