python批量更改文件名

__author__ = 'Samsung'
paths = r"D:\private\picture"
import os
def rename(paths):
    i=1
    print i
    for root, dirs,files in os.walk(paths):
        '''for dirlist in dirs:
            rename(os.path.join(root,dirlist))'''
        for file in files:
            #files include the files in sub dir
            types = file.split('.')[-1]
            #os.rename() need  absolute path
            os.rename(os.path.join(root,file),os.path.join(root,str(i)+'.'+types))

            i += 1


rename(paths)

 

posted @ 2017-05-19 14:16  zhanghaihui  阅读(130)  评论(0编辑  收藏  举报