File size: 630 Bytes
d81e0eb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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}')