首页 > 编程语言 > 详细

Python批量重命名指定文件夹下文件的两种方法

时间:2015-06-10 07:43:43      阅读:319      评论:0      收藏:0      [点我收藏+]
#法一
import os
path = "C://Python34//"
for file in os.listdir(path):
    if os.path.isfile(os.path.join(path,file))==True:
        if file.find('.')<0:
            newname=file+'.jpg'
            os.rename(os.path.join(path,file),os.path.join(path,newname))
            


#法二			
import os
import glob

path = "C://Python34//"
for infile in glob.glob( os.path.join(path, '*.gif') ):
	for i in range (1,21):
		index_symbol = "_" + str(i) + "_"
		if index_symbol in infile:
			newfile = infile
			newfile = newfile.replace(index_symbol, str(i));
			os.rename(infile, newfile)
			print (infile)

Python批量重命名指定文件夹下文件的两种方法

原文:http://blog.csdn.net/vernice/article/details/46436945

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!