importos,string
defs_rename(path,old_ext,new_ext):
for(path, dirs, files) in os.walk(path):
for filename in files:
ext=os.path.splitext(filename)[1]
if(cmp(ext,old_ext)==0):
newname=filename.replace(old_ext,new_ext)
oldpath=path+""+filename
newpath=path+""+newname
print"oldpath:"+oldpath+""
print"newpth:"+newpath+""
try:
os.rename(oldpath, newpath)
exceptValueError:
print"Error when rename the file "+ oldpath
exceptNameError:
print"Error when rename the file "+ oldpath
exceptOSError:
#print OSError
printnewpath + " The file is already exist!"