重命名目录下所有文件

# encoding: utf-8  
import os  
import os.path  
rootdir = r'D:\game'


for parent, dirnames, filenames in os.walk(os.getcwd()):
    for index in range(len(filenames)):
        filename = filenames[index]
        if ".jpg" in filename:
            newName = "haoyou%i.jpg" % index
            os.rename(os.path.join(parent, filenames[index]), os.path.join(parent, newName))

你可能感兴趣的:(重命名目录下所有文件)