Python批量重命名

使用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>

Comments

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×