python更改文件夹下文件名字
''' Created on 2013-1-2 @author: buptlishantao ''' #!/usr/bin/python import re import os import time def change_name(path): global i if not os.path.isdir(path) and not os.path.isfile(path): return False if os.path.isfile(path): file_path = os.path.split(path) #split the path into path name and file name lists = file_path[1].split('.') file_ext = lists[-1] img_ext = ['bmp','jpeg','gif','psd','png','JPG','jpg'] if file_ext in img_ext: os.rename(path,file_path[0]+'/'+lists[0]+'_fc.'+file_ext) i+=1 elif os.path.isdir(path): for x in os.listdir(path): change_name(os.path.join(path,x)) img_dir = os.getcwd() start = time.time() i = 0 print img_dir change_name(img_dir) c = time.time()-start print('time:%0.2f'%(c)) print('number %s '%(i))