File size: 668 Bytes
4312a87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os

# 指定目录路径,替换为你的实际目录路径
directory = r'/home/chengyou/xcl/OminiControl_2conditions_hf5/result_context/COD10K'

# 遍历目录中的所有文件
for filename in os.listdir(directory):
    if filename.endswith('.jpg'):
        # 分割文件名和扩展名
        base = os.path.splitext(filename)[0]
        # 构建新的文件名
        new_filename = base + '.h5'
        # 重命名文件
        os.rename(
            os.path.join(directory, filename),
            os.path.join(directory, new_filename)
        )
        print(f'Renamed: {filename} -> {new_filename}')

print("All .jpg files have been renamed to .h5")