Python实现图片批量重命名+统一改名,简单好用图片整理工具

前言

不管是拍照素材、截图、网图、产品图片,时间久了之后文件名杂乱,全是乱码、数字、英文,查看和使用非常不方便。

手动一个个改名又慢又累,还容易改错顺序。

今天给大家分享一款纯Python写的图片批量重命名工具,不用复杂配置,代码复制就能直接运行,可以统一前缀、有序编号,自动保留图片后缀,安全不损坏原图,零基础也能上手,适合日常自用+发文。

一、实现功能

批量修改文件夹内所有图片名称

自定义统一前缀+数字递增编号

自动保留原图格式后缀不变

只处理图片文件,不会改动其他文档

运行安全,不删除、不损坏原始图片

原生模块实现,无需额外安装复杂依赖

二、运行环境

仅使用Python内置 os 模块

无需pip安装第三方库

Python3 全部版本通用,Windows直接运行

三、完整可运行代码

import os

图片格式筛选列表

img_suffix = ".jpg", ".jpeg", ".png", ".gif", ".bmp", ".webp"

def rename_images(folder_path, prefix="图片"):

count = 1

获取文件夹所有文件

file_list = os.listdir(folder_path)

for file in file_list:

获取文件后缀

suffix = os.path.splitext(file)1.lower()

只处理图片文件

if suffix in img_suffix:

old_path = os.path.join(folder_path, file)

new_name = f"{prefix}_{count}{suffix}"

new_path = os.path.join(folder_path, new_name)

os.rename(old_path, new_path)

print(f"{file} >>> {new_name}")

count += 1

print("图片批量重命名全部完成!")

if name == "main":

在这里修改你的图片文件夹路径

target_folder = r"D:\picture"

自定义改名前缀

name_prefix = "风景素材"

rename_images(target_folder, name_prefix)

四、使用方法

https://gitee.com/nomeans/tea-tasting/issues/IJBSW8

https://gitee.com/nomeans/tea-tasting/issues/IJBSW6

https://gitee.com/nomeans/tea-tasting/issues/IJBSW3

https://gitee.com/nomeans/tea-tasting/issues/IJBSVZ

https://gitee.com/nomeans/tea-tasting/issues/IJBSVW

https://gitee.com/nomeans/tea-tasting/issues/IJBSVT

https://gitee.com/nomeans/tea-tasting/issues/IJBSVS

https://gitee.com/nomeans/tea-tasting/issues/IJBSVO

https://gitee.com/nomeans/tea-tasting/issues/IJBSVJ

https://gitee.com/nomeans/tea-tasting/issues/IJBSVD

https://gitee.com/nomeans/tea-tasting/issues/IJBSV8

https://gitee.com/nomeans/tea-tasting/issues/IJBSV5

https://gitee.com/nomeans/tea-tasting/issues/IJBSV2

https://gitee.com/nomeans/tea-tasting/issues/IJBSV1

https://gitee.com/nomeans/tea-tasting/issues/IJBSUY

https://gitee.com/nomeans/tea-tasting/issues/IJBSUU

https://gitee.com/nomeans/tea-tasting/issues/IJBSUT

https://gitee.com/nomeans/tea-tasting/issues/IJBSUS

https://gitee.com/nomeans/tea-tasting/issues/IJBSUP

https://gitee.com/nomeans/tea-tasting/issues/IJBSUN

https://gitee.com/nomeans/tea-tasting/issues/IJBSUL

https://gitee.com/nomeans/tea-tasting/issues/IJBSUJ

https://gitee.com/nomeans/tea-tasting/issues/IJBSUG

https://gitee.com/nomeans/tea-tasting/issues/IJBSUC

https://gitee.com/nomeans/tea-tasting/issues/IJBSUB

https://gitee.com/nomeans/tea-tasting/issues/IJBSU9

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRZ

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRY

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRX

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRT

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRR

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRP

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRN

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRL

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRI

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRG

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRF

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRE

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRD

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSRA

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSR7

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSR6

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSR1

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQY

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQW

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQV

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQT

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQJ

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQH

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQG

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQF

https://gitee.com/gnoliynil/tea-tasting/issues/IJBSQD

https://gitee.com/jqhph/tea-tasting/issues/IJBSPH

https://gitee.com/jqhph/tea-tasting/issues/IJBSPF

https://gitee.com/jqhph/tea-tasting/issues/IJBSPE

https://gitee.com/jqhph/tea-tasting/issues/IJBSPB

https://gitee.com/jqhph/tea-tasting/issues/IJBSPA

https://gitee.com/jqhph/tea-tasting/issues/IJBSP9

https://gitee.com/jqhph/tea-tasting/issues/IJBSP6

https://gitee.com/jqhph/tea-tasting/issues/IJBSP5

https://gitee.com/jqhph/tea-tasting/issues/IJBSP3

https://gitee.com/jqhph/tea-tasting/issues/IJBSP2

https://gitee.com/jqhph/tea-tasting/issues/IJBSP0

https://gitee.com/jqhph/tea-tasting/issues/IJBSOZ

https://gitee.com/jqhph/tea-tasting/issues/IJBSOV

https://gitee.com/jqhph/tea-tasting/issues/IJBSOU

https://gitee.com/jqhph/tea-tasting/issues/IJBSOT

https://gitee.com/jqhph/tea-tasting/issues/IJBSOP

https://gitee.com/jqhph/tea-tasting/issues/IJBSOL

https://gitee.com/jqhph/tea-tasting/issues/IJBSOK

https://gitee.com/jqhph/tea-tasting/issues/IJBSOJ

https://gitee.com/jqhph/tea-tasting/issues/IJBSOI

https://gitee.com/jqhph/tea-tasting/issues/IJBSO5

https://gitee.com/jqhph/tea-tasting/issues/IJBSO4

https://gitee.com/jqhph/tea-tasting/issues/IJBSO2

https://gitee.com/jqhph/tea-tasting/issues/IJBSNZ

https://gitee.com/jqhph/tea-tasting/issues/IJBSNW

https://gitee.com/jqhph/tea-tasting/issues/IJBSNV

https://gitee.com/wxf8602/tea-tasting/issues/IJBSMS

https://gitee.com/wxf8602/tea-tasting/issues/IJBSMQ

https://gitee.com/wxf8602/tea-tasting/issues/IJBSMO

https://gitee.com/wxf8602/tea-tasting/issues/IJBSMM

https://gitee.com/wxf8602/tea-tasting/issues/IJBSML

https://gitee.com/wxf8602/tea-tasting/issues/IJBSMG

https://gitee.com/wxf8602/tea-tasting/issues/IJBSME

https://gitee.com/wxf8602/tea-tasting/issues/IJBSMD

https://gitee.com/wxf8602/tea-tasting/issues/IJBSM7

https://gitee.com/wxf8602/tea-tasting/issues/IJBSM6

https://gitee.com/wxf8602/tea-tasting/issues/IJBSM4

https://gitee.com/wxf8602/tea-tasting/issues/IJBSM3

https://gitee.com/wxf8602/tea-tasting/issues/IJBSLQ

https://gitee.com/wxf8602/tea-tasting/issues/IJBSLP

https://gitee.com/wxf8602/tea-tasting/issues/IJBSLO

https://gitee.com/wxf8602/tea-tasting/issues/IJBSLL

https://gitee.com/wxf8602/tea-tasting/issues/IJBSLI

https://gitee.com/wxf8602/tea-tasting/issues/IJBSLF

https://gitee.com/wxf8602/tea-tasting/issues/IJBSLD

https://gitee.com/wxf8602/tea-tasting/issues/IJBSL9

https://gitee.com/wxf8602/tea-tasting/issues/IJBSL3

https://gitee.com/wxf8602/tea-tasting/issues/IJBSKX

https://gitee.com/wxf8602/tea-tasting/issues/IJBSKS

https://gitee.com/wxf8602/tea-tasting/issues/IJBSKN

https://gitee.com/wxf8602/tea-tasting/issues/IJBSKJ

https://gitee.com/wxf8602/tea-tasting/issues/IJBSKE

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSH6

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSH5

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSH3

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSH1

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSH0

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSGX

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSGU

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSGQ

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSGM

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSGD

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSGA

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSG7

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSG3

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFY

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFW

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFQ

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFI

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFG

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFD

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFC

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSFB

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSF9

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSF8

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSF7

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSF5

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSF3

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSF2

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEZ

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEY

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEW

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEU

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSET

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSES

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEQ

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEP

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEN

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEM

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEL

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEK

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEI

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEG

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSED

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEB

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSEA

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSE7

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSE5

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSE4

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSE3

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSDT

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSDS

https://gitee.com/sparrowgood/tea-tasting/issues/IJBSDR

新建py文件,把上面代码全部复制进去

修改代码里图片文件夹路径为自己的目录

修改想要统一的中文前缀名称

直接运行代码,自动有序批量改名

五、应用场景

手机导出照片统一规整命名

电商产品图片批量整理

自媒体素材图库分类改名

截图、学习资料图片归档整理

个人相册统一规范化管理

六、优点说明

操作简单,零基础也能使用

速度快,几百张图片几秒完成

原图画质、格式完全不受影响

只针对图片筛选,不会误改其他文件

七、简单拓展思路

增加按修改时间排序后再命名

实现图片批量缩小压缩

自动给图片加上统一水印

递归遍历子文件夹全部图片

八、总结

这款Python图片批量重命名脚本,简单实用、轻量化,是日常整理图库必备的小工具。

告别手动一个个改名字,一键统一格式、有序编号,省心又高效,代码干净无敏感内容,直接复制就能用、能发文。

#Python #Python图片处理 #批量重命名 #办公自动化 #图片整理 #Python小工具 #编程入门

相关推荐
fengyehongWorld2 分钟前
Windows 命令行包管理工具scoop的使用
windows
思麟呀8 分钟前
C++11并发编程:互斥锁
linux·开发语言·c++·windows
xiaoliuliu123451 小时前
LaTeX 2023 (TeX Live + TeXstudio) 安装与汉化教程 Windows版:自定义路径+编辑器配置指南
windows·编辑器
技术达芬奇1 小时前
如何让 WSL 2 在后台持续运行:彻底解决关闭终端后 WSL 退出问题(Hermes Agent 持续运行)
windows·agent
一个人旅程~2 小时前
完整精华版macbookHighSierra 至Montere-Ventyra版本跨越评估与避坑指南(含证书有效期)
windows·经验分享·macos·电脑
Cheng小攸2 小时前
【无标题】
windows
Cheng小攸2 小时前
综合实战(3)
windows·php
bucenggaibian3 小时前
搭建CMD编译C语言环境
linux·c语言·windows
ylscode3 小时前
微软发布针对 Windows 11 的 KB5089573 补丁,以修复“周二补丁日”安装问题
windows·安全·microsoft·安全威胁分析
yaoxin52112313 小时前
419. 现代 Java IO 最佳实践 - 写入文本文件
java·windows·python