You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
623 B
17 lines
623 B
9 months ago
|
import os
|
||
|
|
||
|
folder_path = "C:/Users/yq183/Desktop/img" # 文件夹路径
|
||
|
new_name_prefix = "img_" # 新名称前缀
|
||
|
|
||
|
# 获取文件夹下所有图片文件名
|
||
|
image_files = [f for f in os.listdir(folder_path) if f.endswith(".jpg") or f.endswith(".png")or f.endswith(".jpeg")]
|
||
|
|
||
|
# 遍历所有图片文件,进行重命名
|
||
|
for i, image_file in enumerate(image_files):
|
||
|
old_path = os.path.join(folder_path, image_file)
|
||
|
new_name = f"{new_name_prefix}{i+1}.jpg" # 新名称格式
|
||
|
new_path = os.path.join(folder_path, new_name)
|
||
|
os.rename(old_path, new_path)
|
||
|
|
||
|
print("All images have been renamed successfully!")
|