#!/usr/bin/env python
# encoding: utf-8
import os
def rename(dirname):
filelist = os.listdir(dirname)
count = 0
for file in filelist:
olddir = os.path.join(dirname,file)
if os.path.isdir(olddir):
continue
filename = os.path.splitext(file)[0]
filetype = os.path.splitext(file)[1]
newdir = os.path.join(dirname,str(count)+filetype)
os.rename(olddir,newdir)
count = count + 1
rename("文件目录")
结果: