标签:
1 # -*- coding: utf-8 -*- 2 __author__ = ‘louis‘ 3 4 import os 5 import re 6 7 8 def rename_files(dir_path): 9 i=1 10 print dir_path 11 for fil in dir_list: 12 if os.path.isfile(os.path.join(dir_path, fil)) == True: 13 if re.search(‘.*avi$‘, fil): 14 print fil 15 new_name = str(i)+‘.avi‘ 16 os.rename(os.path.join(dir_path, fil), os.path.join(dir_path, new_name)) 17 i += 1 18 19 if __name__ == ‘__main__‘: 20 print "Hello world" 21 d_path = r"c:\Te" 22 rename_files(d_path) 23 24 dir_list = os.listdir(d_path) 25 print dir_list
标签:
原文地址:http://www.cnblogs.com/haoshine/p/5115079.html