在实际中,经常需要对多个文件夹下的文件或图片进行重新命名。下面就详细地讲解一下如何操作:
import os
def RenameFile(path):
for roots, dirs, files in os.walk(path):n = 0
for file in files:
oldname = os.path.join(roots,file)
newname = roots + '/' + '%d'%(n)+ os.path.splitext(file)[1]
os.rename(oldname, newname)
n +=1
path = 'F:/rename/data'
RenameFile(path)