python 重命名文件

def rename_img(path)
    start = time.clock()#计算程序开始执行
    count=0
    for root,dirs,files in os.walk(path):    #遍历统计
        for each in files:  
            url=path+"\\"+each; #原文件的路径+文件名(绝对路径)
            count=count+1;
            os.rename(url,path+"//N"+str(count)+".jpg")
    elapsed = (time.clock() - start) #计算程序结束
    print("running time:"+str(elapsed)+"s") #显示程序的执行时间

这里将所有的文件命名为:

重命名函数:os.rename(原来绝对路径,现在绝对路径)

猜你喜欢

转载自blog.csdn.net/weixin_39874268/article/details/83048363