Python批量重命名

本文最后更新于 2016年9月14日 下午

使用Python2.7版本

代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# /user/bin/python
# -*- coding=UTF-8 -*-
import os

#执行重命名
path = 'D:\\check\\Images'
for file in os.listdir(path):
if os.path.isfile(os.path.join(path,file))==True:
newname = file.replace("test","a.xml")
os.rename(os.path.join(path,file),os.path.join(path,newname))

#打印文件名列表
for file in os.listdir(path):
if os.path.isfile(os.path.join(path,file))==True:
print file</span>

Python批量重命名
https://yuluod.github.io/2016/09/14/Python批量重命名/
作者
yuluo
发布于
2016年9月14日
许可协议