How to batch rename pictures in timestamp order (Python)

The previous article talked about how to rename pictures in batches (python) , but not in order of timestamps. Therefore, this time, another code was rewritten to rename pictures in chronological order.

#coding=utf-8
import os
path='/home/edward/CLionProjects/ch11/data/'       
f=os.listdir(path)
f.sort()
n=0
string=str(n+1) #将int转换为string,从1开始
#遍历修改每一个文件名
for i in f:
    oldname=path+f[n]
    newname=path+string+'.png'
    os.rename(oldname,newname)
    print(oldname,'------------>',newname)
    n=n+1
    string = str(n+1)

The conversion result is as follows:

 

 Generally speaking, it is relatively smooth, and I hope that another problem will be solved today and tomorrow!

 

Supongo que te gusta

Origin blog.csdn.net/loveSIYU/article/details/114604473
Recomendado
Clasificación