import time
import os
def Change(paths):
if not os.path.isfile(paths) and not os.path.isdir(paths):
print "传递的不是目录或文件"
ahz = ["txt","png"]
if os.path.isdir(paths):
files = os.listdir(paths)
for i in files:
pfile = i.split('.')
hz = pfile[-1]
if hz in ahz:
os.rename(i,pfile[0]+"_"+time.strftime("%Y-%m-%d",time.localtime())+"."+hz)
print "更改目录下的文件完成!"
elif os.path.isfile(paths):
pfile = paths.split('.')
hz = pfile[-1]
if hz in ahz:
os.rename(paths,pfile[0]+"_"+time.strftime("%Y-%m-%d",time.localtime())+"."+hz)
print "更改单个文件完成!"
转载于:https://blog.51cto.com/yangsp805/1200163