**
导入相关库
**
import os
设置图片文件夹的路径
image_folder = " D:\\images"
获取文件夹中的所有图片文件
image_files = [f for f in os.listdir(image_folder) if f.endswith(".jpg")]
确保文件夹中至少有一个图片文件
if not image_files:print("文件夹中没有图片文件.")
else:# 按照顺序重命名图片文件for i, image_file in enumerate(image_files, 1):# 构建新的文件名new_name = f"{i}.jpg"# 获取旧文件的完整路径和新文件的完整路径old_path = os.path.join(image_folder, image_file)new_path = os.path.join(image_folder, new_name)# 重命名文件os.rename(old_path, new_path)print(f"重命名 {image_file} 为 {new_name}")print("重命名完成.")