码迷,mamicode.com
首页 > 编程语言 > 详细

python之对指定目录文件夹的批量重命名

时间:2015-04-29 16:42:27      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

python之对指定目录文件夹的批量重命名

import os,shutil,string
dir = "/Users/lee0oo0/Documents/python/test"                                      #指定的目录
for i in os.listdir(dir):   #遍历指定目录的文件
    newfile = i.replace(a,b)                                # 替换
    oldname = dir +/+str(i)
    newname = dir +/+str(newfile)
    shutil.move(oldname,newname)    # 重命名
print("finish")

 

python之对指定目录文件夹的批量重命名

标签:

原文地址:http://www.cnblogs.com/lee0oo0/p/4466090.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!