import os def rename_images_in_folder(root_folder): # 遍历根目录 for root, dirs, files in os.walk(root_folder): if not dirs: # 检查当前目录下是否有子目录,没有则表示是底层子文件夹 count = 1 for file in files: file_path = os.path.join(root, file) file_extension = os.path.splitext(file)[1].lower() if file_extension in ['.png', '.jpg', '.jpeg', '.gif', '.bmp']: # 确认文件是图片 new_file_path = os.path.join(root, f"{count}{file_extension}") os.rename(file_path, new_file_path) count += 1 if __name__ == "__main__": folder_path = input("请输入大文件夹的地址: ") rename_images_in_folder(folder_path) print("图片重命名完成!")
标签:__,...,os,root,MJ,file,path,folder,伪造 From: https://www.cnblogs.com/zly324/p/18232958