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)
相關文章
相關標籤/搜索