import os
file=os.listdir(".")
for filename in file:
pos=filename.find(".")
if filename[pos+1:]=="doc":
newname=filename[:pos+1]+"wps"
os.rename(filename,newname)
file=os.listdir(".")
for filename in file:
pos=filename.find(".")
if filename[pos+1:]=="doc":
newname=filename[:pos+1]+"wps"
os.rename(filename,newname)
第二种实现:
file=os.listdir(".")
for filename in file:
li=os.path.splitext(filename)
if li[1]==".xls":
newname=li[0]+".wps"
os.rename(filename,newname)
for filename in file:
li=os.path.splitext(filename)
if li[1]==".xls":
newname=li[0]+".wps"
os.rename(filename,newname)